recursive malloc 
Author Message
 recursive malloc

        I don't suppose there's any nice way to recursively malloc
through a structure.  Meaning malloc space for a structure with many
pointers to other structures in it, and having malloc for those
pointers happen automatically.  

        Eric Enockson



Wed, 05 Jan 2000 03:00:00 GMT  
 recursive malloc



Quote:
>    I don't suppose there's any nice way to recursively malloc
>through a structure.  Meaning malloc space for a structure with many
>pointers to other structures in it, and having malloc for those
>pointers happen automatically.  

C++ does that sort of thing (recursive constructors), but not C.
In C, the cleanest approach is to write a struct-specific allocation
function (which can in turn invoke other allocation functions for
substructures).  Be careful not to touch data in any object
before it is allocated or after it is freed.  (I made the latter
error once in the first version of my dirent implementation, and
the bug surfaced only after it was ported to a new platform.)


Thu, 06 Jan 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Recursive to non-recursive

2. Malloc 2: The revenge of Malloc

3. malloc vs 'no-malloc' - help

4. C question : redefining a new malloc() calling standard malloc()

5. to malloc() or not to malloc(), that is the question

6. malloc crashes - malloc(256) returns 0(!) (_MT)

7. Asynchronous socket & recursive receiving

8. how get rid of recursive checkout?

9. Recursive program that evaluate a postfix expression

10. recursive solution for counting summations

11. Recursive directory tree reading

12. Help: C++ and recursive functions

 

 
Powered by phpBB® Forum Software