nn::nex::MemoryManager::SetBasicMemoryFunctions Member Function

Syntax

static void SetBasicMemoryFunctions(
     MallocFunction fcnMalloc,
     FreeFunction fcnFree
);

Parameters

Name Description
in fcnMalloc User-defined memory allocation function.
in fcnFree User-defined memory deallocation function.

Return Values

None.

Description

Sets the functions for allocating and deallocating memory to be used by the entire NEX library.

The NEX library frequently performs dynamic memory allocation internally, but the memory manager can be replaced with this function.

If you use this function, you can change the memory manager used by the NEX library to use original developer code. This function can be called at any time, but usually it is called before an NEX object is created.

The decision whether to use a thread-safe memory manager or thread-unsafe memory manager is left up to the application.

If you are using the NEX library in non-single thread mode, the memory manager used as a replacement must be thread-safe.

Even if you are using the NEX library in single-thread mode, the application itself must be able to operate in a multi-thread environment, and you must pay close attention when an NEX library object is being used in multiple threads. Even when NEX library objects are used as automatic variables (objects created on a stack), in some cases dynamic memory allocation is carried out inside the object. Appropriate exclusive control is required if you are using a thread-unsafe memory manager.

The NEX library includes code that presumes dynamic memory allocation always succeeds. For this reason, make sure that your implementation returns a valid memory address. Specifically, it needs to be implemented as follows.

• Shut down the library if you are going to allocate more memory than has been prepared.

• Use Alloc to allocate several KB in advance, enough to run until the library can be shut down normally. If Alloc cannot be performed, deallocate that memory. Then shut down the library.

• Have plenty of memory available in advance. (Please conduct enough debugging to make sure that memory does not run out, for example, in situations where the communication environment deteriorates).

Revision History

2011/01/27
Initial version.

CONFIDENTIAL