Available in LEADTOOLS Medical Imaging toolkits. |
L_DicomSetMemoryAllocation
#include "ltdic.h"
L_LTDIC_API L_UINT16 EXT_FUNCTION L_DicomSetMemoryAllocation(nType)
L_UINT16 nType; |
/* type of memory allocation */ |
Sets the memory allocation method used in the dicom library. This function is available in the Medical Suite toolkits.
Parameter |
Description |
|
nType |
Type of memory allocation. Possible values are: |
|
|
Value |
Meaning |
|
MEMORY_FAR |
Memory allocated using malloc(). This is the default. This method is fast, but objects allocated with this method can not be modified in other DLLs. |
|
MEMORY_GLOBAL |
Memory allocated using the Windows C DLL GlobalAlloc(). This method is slower than the default. Objects allocated with this method can be modified in other DLLs. |
Returns
MEMORY_FAIL |
Failed to change the method of memory allocation. |
MEMORY_FAR |
Previous method of memory allocation was malloc() |
MEMORY_GLOBAL |
Previous method of memory allocation was GlobalAlloc() |
Comments
In most cases, you do not need to call this function. However if your application consists of multiple processes as in the case of multiple DLLs, and you need to pass pointers to objects allocated inside the current DLL to other processes that will eventually free those objects, then you will need to call this function with the MEMORY_GLOBAL flag (preferably at the beginning of your application) to ensure proper behavior. For example if you are creating a DICOM dataset inside your application and you want to pass a pointer to that dataset to a method inside a COM object which will modify that dataset then you need to call this function with the MEMORY_GLOBAL flag.
Note: |
This function should be used carefully. Objects created with MEMORY_FAR should only be modified with MEMORY_FAR . Likewise, objects created with MEMORY_GLOBAL should only be modified with MEMORY_GLOBAL. Do not create Dicom objects with one type of memory allocation, change the memory allocation method, and then modify the original object. |
Required DLLs and Libraries
LTDIC For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application |
Win32, x64
See Also
Functions: |
L_DicomFreeDS, L_DicomInitDS, L_DicomLoadDS, L_DicomCreateDS |
Topics: |
Example
This example sets the memory allocation method to GlobalAlloc() and displays the previous memory allocation method.
L_INT DicomSetMemoryAllocationExample(L_VOID) { L_UINT16 uRet; L_TCHAR *pszPrev = TEXT(""); uRet = L_DicomSetMemoryAllocation(MEMORY_GLOBAL); switch(uRet) { case MEMORY_FAR: pszPrev = TEXT("Previous memory allocation method: malloc"); break; case MEMORY_GLOBAL: pszPrev = TEXT("Previous memory allocation method: GlobalAlloc"); break; case MEMORY_FAIL: pszPrev = TEXT("L_DicomSetMemoryAllocation failed--invalid parameter"); break; default: pszPrev = TEXT("Undefined error"); } MessageBox(NULL, pszPrev, TEXT(""), MB_OK); return DICOM_SUCCESS; }