L_DicomSetMemoryAllocation

Summary

Sets the memory allocation method used in the dicom library.

Syntax

#include "ltdic.h"

L_LTDIC_API L_UINT16 EXT_FUNCTION L_DicomSetMemoryAllocation(nType)

Parameters

L_UINT16 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 API GlobalAlloc(). This method is slower than the default. Objects allocated with this method can be modified in other DLLs.

Returns

Value Meaning
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

Platforms

Win32, x64, Linux.

See Also

Functions

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; 
} 

Help Version 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DICOM C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.