c++ - Setting memory on a custom heap -
Is it possible to take a Happ handle from Haptet () and set all the available memory for a certain value?
I have tried to calculate the heap from the area and have tried to set it in this way, but I get access violation.
I basically want to set the memory in a custom value which I can use for debugging it, before finally being destroyed through the podistore.
The short answer is "No, you can not fill the heap with a specific value"
You can wrap your HAP Access function with debug versions, for example
// #define HeapAlloc (a, b, c) MyHeapAlloc (a, B) in some header files , C, __FILE__, __LINE__) #HapFree (a, b, c) MyHeapFree (a, b, c, __FILE__, __LINE__) ... in a separate source file: #ifdef HeapAlloc #undef HeapAlloc #undef HeapFree #endif stru Extra {Extra * Next; Size_t size; Const char * file; Int line; }; Extra * head; LPVOD MyHeapOloc (Handle Hep, Dedworld Flags, SIZE_T Size, Const Four * File, Intline) {LPVOID Ridge = HeapAlok (Stack, Flags, Size + Size (Extra)); If (! Res) {cout & lt; & Lt; "Allocation failed, called from" & lt; & Lt; File & lt; & Lt; ":" & Lt; & Lt; Line & lt; & Lt; Endl; Return 0; } Extra * p = reinterpret_cast & lt; Extra * & gt; (Res); Res = reinterpret_cast & lt; Zero * & gt; (& amp; amp; P [1]); P-> Next = head; P-> Size = size; P-> File = file; P-> line = row; Memets (race, 0xAA, size); Withdrawal reserve; } BOOL MyHeapFree (Handle Hep, DWSR Flag, LPVOID Mem, Conquer Four * File, Intline) (Additional * P = Reenter_Plast & lt; Extra * & gt; (MEM); P = reinterpret_cast & lt; void * & gt; (And p [-1]); extra * q = head; extra * prev = 0; while (q) {if (reinterpret_cast (& amp; q [1]) == mem) {Brake;} Prev = q; Q = Next;} If (! Q) {cout & lt; & lt; "attempt to free the memory that has not been assigned to" next = q-> next;} and {head = q-> next;} memeset (mem, 0x bb, q- & gt; Size); Return HipFree (Stack, Flags, Reentit_Cast (q);} I just typed it in, so there may be a modest typo , But hopefully this will show you how to deal with memory allocation. For some cases, you need 16 or 32 bytes to ensure the alignment of the following data. One may have to More Straight pad to be more. Dump the list written by head to see if what has been allocated.
Comments
Post a Comment