mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-07-13 21:51:16 +02:00
metadata union
This commit is contained in:
@@ -97,7 +97,13 @@ typedef struct _MIHP_HeapMemoryAreaHeader
|
||||
|
||||
typedef struct _MIHP_AllocationCustomMetadata
|
||||
{
|
||||
uint8_t data[16];
|
||||
union
|
||||
{
|
||||
uint8_t AsU8 [sizeof(size_t) * 2];
|
||||
uint16_t AsU16 [sizeof(size_t) * 1];
|
||||
uint32_t AsU32 [sizeof(size_t) / 2];
|
||||
uint64_t AsU64 [sizeof(size_t) / 4];
|
||||
};
|
||||
} MIHP_AllocationCustomMetadata;
|
||||
|
||||
typedef struct _MIHP_HeapSegmentHeader
|
||||
|
||||
@@ -62,7 +62,7 @@ int main()
|
||||
|
||||
MIHP_AllocationCustomMetadata metadata = { 0 };
|
||||
void* ptr = GetThisAddress();
|
||||
memcpy(&metadata.data, &ptr, sizeof(void*));
|
||||
memcpy(&metadata.AsU8, &ptr, sizeof(void*));
|
||||
|
||||
MIHP_SetPointerCustomMetadata(&myHeap, myptrs[i], metadata);
|
||||
MIHP_ValidateHeap(&myHeap);
|
||||
@@ -71,7 +71,7 @@ int main()
|
||||
MIHP_GetPointerCustomMetadata(&myHeap, myptrs[i], &outMetadata);
|
||||
void* returnPtr;
|
||||
|
||||
memcpy(&returnPtr, &outMetadata.data, sizeof(void*));
|
||||
memcpy(&returnPtr, &outMetadata.AsU8, sizeof(void*));
|
||||
|
||||
MIHP_ASSERT(ptr == returnPtr);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user