alloca

Allocates memory space for a block of memory on the stack

Local Servers:nonblocking
Remote Servers:N/A
Classification:Other
Service:Memory Allocation

Syntax

  #include <nwmalloc.h> 
    
  void *alloca  (  
        size_t   size);
  

Parameters

size
(IN) Specifies the size (in bytes) of the block of memory.

Return Values

alloca returns a pointer to the start of the allocated memory. The return value is NULL if insufficient memory is available or if the value of the size parameter is 0.

Remarks

Memory allocation is not limited to 64 KB. The size parameter is 32 bits.

The alloca function allocates memory space for an object of size bytes from the stack. The allocated space is automatically discarded when the current function exits.

The alloca function should not be used in an expression that is an argument to a function, because the alloca function manipulates the stack.

See Also

free, malloc, NWGarbageCollect (NDK: NLM Development Concepts, Tools, and Functions)

Example

     #include stdio.h 
     #include string.h 
     #include nwmalloc.h 
     FILE   *open_err_file (char *name) 
        { 
           char *buffer;     /* Allocate temp buffer for file name */ 
           buffer = alloca (strlen (name) + 5);- 
           if (buffer) 
           { 
              sprintf ("buffer, %s.err", name); 
              return (fopen (buffer, "w") ); 
           } 
           return (NULL); 
        }