Hi,
can you please explain to me how the Value class work
Code:
class Value
{
private:
public:
void * buffer;
int buffersize;
void operator=(int v) { memcpy(buffer, &v, buffersize); }
void operator=(double v) { memcpy(buffer, &v, buffersize); }
void operator=(const char *v) { strncpy((char*)buffer, v, buffersize-1); /*buffer[buffersize-1]='\0';*/ }
};
When does buffersize get set?
One thing we should remember is to free memory after assigning it to a value. Let me explain via code:
Code:
char *Name( void )
{
char *Result = new char [ 32 ] ;
memset( Result, 0, 32 ) ;
sprintf( Result, "Rudi Grobler" ) ;
return Result ;
}
Now in the plug in we have a case statement that checks which variable you want and then returns it...
Code:
case 0:
value = Name( ) ;
break ;
This will cause a memory leak!!!
Code:
case 0:
char *Result = Name( ) ;
value = Result ;
delete Result ;
break ;
I know this might seem simple to some but I hade some problems with memory leaks and thought I should atleast share it so that a newbe dont have the same problems!!!