Arena storage pool: Difference between revisions

(added omit from ML/I)
Line 97:
Uninitialized memory is allocated using the malloc function. To obtain the amount of memory that needs to be allocated, sizeof is used. Sizeof is not a normal C function, it is evaluated by the compiler to obtain the amount of memory needed.
<lang c>int *var = malloc(n*sizeof(int));
Typename *var = malloc(sizeof (Typename));
Typename *var = malloc(sizeof( var[0]));</lang>
Since pointers to structures are needed so frequently, often a
typedef will define a type as being a pointer to the associated structure.
Line 118:
One can allocate space on the stack using the alloca() function. You do not
free memory that's been allocated with alloca
<lang c>Typename *var = alloca(sizeof (Typename));</lang>
An object oriented approach will define a function for creating a new object of a class.
In these systems, the size of the memory that needs to be allocated for an instance of the
Anonymous user