Allocate memory.
CS_VOID *srv_alloc(size) CS_INT size;
The number of bytes to allocate.
Returns |
To indicate |
---|---|
A pointer to the newly allocated space |
The location of the new space. |
A null CS_VOID pointer |
Open Server could not allocate size bytes. |
#include <ospublic.h>
/*
** Local Prototype
*/
CS_RETCODE ex_srv_alloc PROTOTYPE((
CS_BYTE **bpp,
CS_INT size
));
/*
** EX_SRV_ALLOC
**
** Example routine to allocate the specified amount of memory
** using srv_alloc.
**
** Arguments:
** bpp Return pointer to allocated memory here.
** size Amount of memory to allocate.
**
** Returns:
**
** CS_SUCCEED Memory was allocated successfully.
** CS_FAIL An error was detected.
*/
CS_RETCODE ex_srv_alloc(bpp, size)
CS_BYTE **bpp;
CS_INT size;
{
/* Initialization. */
*bpp = (CS_BYTE *)NULL;
/*
** Allocate size number of bytes.
*/
if((*bpp = (CS_BYTE *)srv_alloc(size)) == (CS_BYTE *)NULL)
{
return(CS_FAIL);
}
return(CS_SUCCEED);
}
/*
** Allocate size number of bytes.
*/
if((*bpp = (CS_BYTE *)srv_alloc(size)) == (CS_BYTE *)NULL)
{
return(CS_FAIL);
}
return(CS_SUCCEED);
}
srv_alloc allocates memory dynamically. It returns a pointer to size bytes if that many bytes are available.
Any memory allocated using srv_alloc should be freed by calling srv_free.
Use srv_alloc wherever the standard C memory allocation routines would be used.
Currently, srv_alloc calls the C routine, malloc. An Open Server application, however, can install its own memory management routines using the srv_props routine. The parameter-passing conventions of the user-installed routines must be the same as those of malloc. If the application is not configured to use user-installed routines, Open Server will call malloc.