Coder's Guild Mailing List

Re: memory management in C.....

Posted by James Steele on 2001-04-17

If you want my opinion, use 'new' and 'delete'.  To me, it's simpler than messing around 
with the functions, as 'new' automatically calculates how much to allocate on its own, and 
'delete' knows how much to deallocate on its own.  No need to tell it.  Last I checked, 
new and delete should be supported by both C and C++ compilers.

But shouldn't this:

apointer = malloc(sizeof(your_classname));

work?

/********************/

> hi everybodi...
> 
>  i 'm having a structure which contains sum chars ,ints ,doubles & pointers as 
> elements...
>  
>  now i want to allocate a big chunk of memory using malloc so that the memory 
> allocated is just enough to hold all the members of the structure including the 
> memory space pointed to by the member pointers ..how this kin be done so that 
> memory wasted is minimum (since ,i think malloc always take care of aligning a 
> double at a word boundary)...And also how kin i make the member pointers to 
> point to sum parts of the memory from that allocated big chunk onli...
>  
>  thanks in advance...
>  
> bi...bi...
> with luv...
> pradeep...