|
| iMatix home page | << | < | > | >> |
SFLVersion 2.10 |
#include "sflmem.h"
void *
mem_alloc_ (
MEMTRN *trn, /* Associated transaction */
size_t size, /* Desired size of memory block */
const char *filename, /* Name of source file making call */
size_t lineno /* Line number in calling source */
)
Allocates a memory block. Use the mem_alloc() macro to call this function! Use mem free () to free blocks allocated with this function. Returns a pointer to the allocated memory block, or NULL if there was not enough memory available. The supplied source file name is assumed to be in a static area. The requested block size must be greater than zero bytes.
{
MEMHDR
*ptr; /* Allocated memory block */
/* Allocate block with extra space for the header */
ASSERT (size > 0); /* Cannot allocate zero bytes! */
ptr = malloc (RESERVE_SIZE + size);
if (ptr == NULL) /* If nothing free, do a hunt */
{ /* and try again... */
mem_scavenge ();
ptr = malloc (RESERVE_SIZE + size);
if (ptr == NULL)
return (NULL); /* Really in trouble now! */
}
# if (defined (MEM_TRACE))
trace ("%s (%d): alloc %d bytes->%p",
filename? filename: "-", lineno, size, ptr);
# endif
ptr-> tag = MEMTAG; /* Initialise block header */
ptr-> size = size; /* Size of block */
ptr-> file = filename; /* Who allocated it */
ptr-> line = lineno; /* and where */
if (!trn) /* If no transaction then use the */
trn = &mem_list; /* main block list */
list_reset (ptr); /* Set up new block as list */
list_relink_before (ptr, /* Add to list of blocks */
&trn-> memhdr);
mem_total += size; /* Keep count of space used */
mem_alloc_count += 1; /* and number of allocations */
return (HDR_2_CLIENT (ptr)); /* and return client address */
}
| | << | < | > | >> |
|