DosFreeThreadLocalMemory: Difference between revisions
Appearance
Created page with "==Description== Frees a block of thread-local memory that was originally allocated using DosAllocThreadLocalMemory. ==Syntax== <PRE> #define INCL_DOSPROCESS #include <os2.h> ..." |
mNo edit summary |
||
Line 7: | Line 7: | ||
#include <os2.h> | #include <os2.h> | ||
ULONG *p; /* | ULONG *p; /* Address of the memory block to free. */ | ||
APIRET rc; /* | APIRET rc; /* Return Code. */ | ||
rc = DosFreeThreadLocalMemory(p); | rc = DosFreeThreadLocalMemory(p); | ||
</PRE> | |||
==Parameters== | ==Parameters== | ||
; | ; p (ULONG *) - input : Address of the memory block to free. | ||
==Return Code== | ==Return Code== | ||
rc (APIRET) - returns | rc (APIRET) - returns | ||
This function returns one of the following values: | This function returns one of the following values: | ||
* 0 NO_ERROR | |||
* 0 | * 87 ERROR_INVALID_PARAMETER | ||
* 87 | |||
==Remarks== | ==Remarks== | ||
Line 30: | Line 29: | ||
==Example Code== | ==Example Code== | ||
This example shows how to allocate and free 3 DWORDs of local thread memory. | This example shows how to allocate and free 3 DWORDs of local thread memory. | ||
<PRE> | <PRE> | ||
#define INCL_DOSPROCESS | #define INCL_DOSPROCESS | ||
Line 63: | Line 61: | ||
return NO_ERROR; | return NO_ERROR; | ||
} | } | ||
</PRE> | |||
==Related Functions== | ==Related Functions== | ||
* [[ | *[[DosAllocThreadLocalMemory]] | ||
[[Category: | [[Category:Dos]] |
Revision as of 20:38, 26 November 2016
Description
Frees a block of thread-local memory that was originally allocated using DosAllocThreadLocalMemory.
Syntax
#define INCL_DOSPROCESS #include <os2.h> ULONG *p; /* Address of the memory block to free. */ APIRET rc; /* Return Code. */ rc = DosFreeThreadLocalMemory(p);
Parameters
- p (ULONG *) - input
- Address of the memory block to free.
Return Code
rc (APIRET) - returns
This function returns one of the following values:
- 0 NO_ERROR
- 87 ERROR_INVALID_PARAMETER
Remarks
When a process is started, a small block of memory is set aside to be used as a thread-local memory area. This memory is at the same virtual address for each thread, but is backed by different physical memory. This permits each thread to have a small block of memory that is unique, or local, to that thread.
The thread-local memory area consists of 32 DWORDs (128 bytes), each DWORD being 32-bits in size.
Example Code
This example shows how to allocate and free 3 DWORDs of local thread memory.
#define INCL_DOSPROCESS #define INCL_DOSERRORS #include <os2.h> #include <stdio.h> /* Needed for printf */ PULONG pulThreadDWords = NULL; /* Pointer to thread DWORDs returned */ APIRET rc = NO_ERROR; /* Return code */ int main(VOID) { /* Allocate 3 DWORDs of local thread memory */ rc = DosAllocThreadLocalMemory(3, /* Number of DWORDs */ &pulThreadDWords); /* Address returned */ if (rc != NO_ERROR) { printf("DosAllocThreadLocalMemory error: return code = %u\n", rc); return 1; } /* ... Use the thread-local memory ... */ rc = DosFreeThreadLocalMemory(pulThreadDWords); /* Free the DWORDs */ if (rc != NO_ERROR) { printf("DosFreeThreadLocalMemory error: return code = %u\n", rc); return 1; } return NO_ERROR; }