2.5 Memory Allocation and Management

LibC surfaces both typed and untyped memory, although there are peculiar semantics across the NetWare kernel and user (protected) address spaces. To be portable, services are expected to manage their memory needs carefully.

Untyped memory is potentially pageable unless paging is explicitly prohibited by calling NXMemCtl. Virtual memory that is allocated and not locked down by an NLM running in ring 0 (the kernel) opens execution to preemption. All execution is open to preemption when the NLM is running in a user address space.

2.5.1 Memory Interfaces

LibC contains four types of memory interfaces:

  • Standard ANSI. LibC contains all the standard memory functions (calloc, free, malloc, and realloc) and a few common functions (alloca, msize, and stackavail).

  • NKS. The NKS memory functions allocate, reallocate, and free memory similarly to malloc, realloc, and free. However, they accept a parameter to specify alignment requirements that, on some platforms, can be an important performance variable. See NXMemAlloc, NXMemFree, and NXMemRealloc.

    Other functions enable you to allocate whole pages of memory and to control the state of that memory, whether locked or not (see NXMemCtl, NXPageAlloc, and NXPageFree). The page allocation functions do not fail when there is no virtual memory subsystem present; they just allocate large chunks of locked-down, normal memory.

  • Library. The library memory functions are designed to be used by third-party libraries.These functions allow the resources to be attributed to the library NLM rather than to the NLM of the calling thread. For more information, see Obtaining Information about Loaded NLMs in Volume 2.

  • NetWare Resource Tag Memory. The NetWare operating system tracks the memory that each NLM uses. To have it track that memory for a particular component of your NLM, you allocate a resource tag (see AllocateResourceTag) and then allocate memory for that resource tag (Alloc or AllocSleepOK). The NetWare operating system also has specialized functions for memory above 4 GB (see ESMAlloc).

2.5.2 Memory Leaks

Besides the memory you allocate directly by calling one of the memory interfaces, some LibC functions allocate memory for you. For example, if you call getcwd with NULL as the path parameter, LibC allocates enough memory to hold the path to the current working directory. You are responsible for freeing this memory.

For help in tracking memory leaks, see Tracking Memory Leaks with LibC.