Summary
Allocates memory from the browser's memory space.
Syntax
#include <npapi.h> void *NPN_MemAlloc (uint32 size);
Parameters
The function has the following parameters:
- size
- Size of memory, in bytes, to allocate in the browser's memory space.
Returns
- If successful, the function returns a pointer to the allocated memory, in bytes.
- If insufficient memory is available, the plug-in returns null.
Description
The plug-in calls NPN_MemAlloc
to allocate a specified amount of memory in the browser's memory space. If you allocate saved instance data with NPP_Destroy, be sure to use NPN_MemAlloc
to allocate memory. This ensures that the browser can free the saved data at a later time with the equivalent of NPN_MemFree.
Since the browser and plug-ins share the same memory space, NPN_MemAlloc
allows plug-ins to take advantage of any customized memory allocation scheme the application may have, and allows the application to manage its memory more flexibly and efficiently.
Mac OS
NPN_MemAlloc
is particularly important on Mac OS, since the Mac OS version of the browser frequently fills its memory partition with cached data that is only purged as necessary. Since NPN_MemAlloc
automatically frees cached information if necessary to fulfill the request, calls to NPN_MemAlloc
may succeed where direct calls to NewPtr fail.
Existing calls to NPN_MemFlush have no effect. You only need to use NPN_MemFlush in situations where you cannot use NPN_MemAlloc
, for example, when calling system methods that allocate memory indirectly.