Created
April 17, 2016 17:44
-
-
Save emoon/ea8fcea7d5f9f01e5a559c2050edd394 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Memory* makeRef(const void* _data, uint32_t _size, ReleaseFn _releaseFn, void* _userData) | |
{ | |
MemoryRef* memRef = (MemoryRef*)BX_ALLOC(g_allocator, sizeof(MemoryRef) ); | |
memRef->mem.size = _size; | |
memRef->mem.data = (uint8_t*)_data; | |
memRef->releaseFn = _releaseFn; | |
memRef->userData = _userData; | |
printf("make makeRef %p\n", &memRef->mem); | |
return &memRef->mem; | |
} | |
bool isMemoryRef(const Memory* _mem) | |
{ | |
return _mem->data != (uint8_t*)_mem + sizeof(Memory); | |
} | |
void release(const Memory* _mem) | |
{ | |
BX_CHECK(NULL != _mem, "_mem can't be NULL"); | |
Memory* mem = const_cast<Memory*>(_mem); | |
if (isMemoryRef(mem) ) | |
{ | |
MemoryRef* memRef = reinterpret_cast<MemoryRef*>(mem); | |
printf("free memRef (%p) releaseFn %p\n", memRef, memRef->releaseFn); | |
if (NULL != memRef->releaseFn) | |
{ | |
memRef->releaseFn(mem->data, memRef->userData); | |
} | |
} | |
BX_FREE(g_allocator, mem); | |
} | |
------------------------------------------------- | |
make makeRef 0x7fc12ac2b710 | |
make makeRef 0x7fc12ac2aa10 | |
make makeRef 0x7fc12ac291c0 | |
make makeRef 0x7fc12ac0cbb0 | |
make makeRef 0x7fc12ac03b10 | |
make makeRef 0x7fc12ac32370 | |
make makeRef 0x7fc12ac03140 | |
make makeRef 0x7fc12ac02350 | |
make makeRef 0x7fc12ac02520 | |
make makeRef 0x7fc12ac03030 | |
make makeRef 0x7fc12ac02730 | |
free memRef (0x7fc12ac2b710) releaseFn 0x0 | |
free memRef (0x7fc12ac2aa10) releaseFn 0x0 | |
free memRef (0x7fc12ac291c0) releaseFn 0x0 | |
free memRef (0x7fc12ac0cbb0) releaseFn 0x0 | |
free memRef (0x7fc12ac03b10) releaseFn 0x0 | |
free memRef (0x7fc12ac32370) releaseFn 0x0 | |
free memRef (0x7fc12ac03140) releaseFn 0x0 | |
free memRef (0x7fc12ac02350) releaseFn 0x0 | |
free memRef (0x7fc12ac02520) releaseFn 0x0 | |
free memRef (0x7fc12ac03030) releaseFn 0x0 | |
free memRef (0x7fc12ac02730) releaseFn 0x0 | |
free memRef (0x7fc12c810330) releaseFn 0x7fc12c810002 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment