heapalloc

Is there a fundamental difference between malloc and HeapAlloc (aside from the portability)?

十年热恋 提交于 2019-12-19 02:27:13
问题 I'm having code that, for various reasons, I'm trying to port from the C runtime to one that uses the Windows Heap API. I've encountered a problem: If I redirect the malloc / calloc / realloc / free calls to HeapAlloc / HeapReAlloc / HeapFree (with GetProcessHeap for the handle), the memory seems to be allocated correctly (no bad pointer returned, and no exceptions thrown), but the library I'm porting says "failed to allocate memory" for some reason. I've tried this both with the Microsoft

HeapCreate and HeapAlloc Confuse

戏子无情 提交于 2019-12-13 18:25:31
问题 I am doing a project on dynamic memory management. I run into a confuse about the HeapCreate and HeapAlloc functions. For the HeapCreate() function, we can create a heap and the function will return a HANDLE. We can initialize the size of heap. Let's say winHandle = HeapCreate( 0, 2 * 1024, 0); Then, I can the HeapAlloc function to allocate on this heap. But I am confuse about the size of the heap. I try an example, I call the HeapAlloc( winHandle, 0, 1024) twice on this heap, so the total

MASM dll memory allocation

ε祈祈猫儿з 提交于 2019-12-11 06:38:54
问题 I need help with my MASM dll. I'm counting elements in array then I want to allocate memory for another array, in C I'm using vector. I tried to use: invoe GetProcessHeap invoke HeapAlloc, eax, HEAP_NO_SERIALIZE + HEAP_ZERO_MEMORY, <size> or invoke GlobalAlloc, GMEM_ZEROINIT, <size> mov tab, eax but I'm getting errors undefined symbol : GetProcessHeap undefined symbol : HeapAlloc I'm using this library in C# application. Can you show me example how can I dynamically allocate memory? 回答1: You

(C) how does a heap allocator handle a 4-byte block header, while only returning addresses that are multiples of 8?

≡放荡痞女 提交于 2019-12-05 06:55:11
问题 It doesn't seem to make sense, unless we just ignore any potential excess space at the beginning of a segment, and then have the first allocated chunk be at the first multiple of 8 (with its corresponding first header being that address -4). This would leave however many bytes before that unused. Is that what's generally done? edit: thanks to paxdiablo for the detailed explanation below. that all makes sense for 16 byte headers. however, i'm working with a 4 byte header, that looks something

(C) how does a heap allocator handle a 4-byte block header, while only returning addresses that are multiples of 8?

余生颓废 提交于 2019-12-03 21:30:02
It doesn't seem to make sense, unless we just ignore any potential excess space at the beginning of a segment, and then have the first allocated chunk be at the first multiple of 8 (with its corresponding first header being that address -4). This would leave however many bytes before that unused. Is that what's generally done? edit: thanks to paxdiablo for the detailed explanation below. that all makes sense for 16 byte headers. however, i'm working with a 4 byte header, that looks something like this: struct mhdr { int size; // size of this block } tMallocHdr; now, if my heap starts on an

malloc returns NULL and sets errno to ENOMEM, but there is plenty of heap space available?

北战南征 提交于 2019-12-01 09:22:08
I have a situation in which malloc() returns NULL and sets errno to ENOMEM . But the CRT heap (which is growable) has plenty of memory to work with. At the time of malloc , my process memory is about 900 MB. The host process is a Java executable executed under the Sun HotSpot JVM. The malloc() I'm doing is 80 megabytes, and fails. If I do a 60 MB allocation, it succeeds. After that, a 50 MB allocation, followed by another one, and another one also succeed : clearly, I still have a lot of memory left but the 80 MB malloc seems too "big" to digest for the OS. I'm using Windows 7 x64 SP1 with 4

malloc returns NULL and sets errno to ENOMEM, but there is plenty of heap space available?

一曲冷凌霜 提交于 2019-12-01 06:19:00
问题 I have a situation in which malloc() returns NULL and sets errno to ENOMEM . But the CRT heap (which is growable) has plenty of memory to work with. At the time of malloc , my process memory is about 900 MB. The host process is a Java executable executed under the Sun HotSpot JVM. The malloc() I'm doing is 80 megabytes, and fails. If I do a 60 MB allocation, it succeeds. After that, a 50 MB allocation, followed by another one, and another one also succeed : clearly, I still have a lot of

Is there a fundamental difference between malloc and HeapAlloc (aside from the portability)?

人盡茶涼 提交于 2019-11-30 20:22:17
I'm having code that, for various reasons, I'm trying to port from the C runtime to one that uses the Windows Heap API. I've encountered a problem: If I redirect the malloc / calloc / realloc / free calls to HeapAlloc / HeapReAlloc / HeapFree (with GetProcessHeap for the handle), the memory seems to be allocated correctly (no bad pointer returned, and no exceptions thrown), but the library I'm porting says "failed to allocate memory" for some reason. I've tried this both with the Microsoft CRT (which uses the Heap API underneath) and with another company's run-time library (which uses the