/** Frees a portion of memory allocated with orxMemory_Allocateate * @param[in] _pMem Pointer on the memory allocated by orx */ void orxFASTCALL orxMemory_Free(void *_pMem) { /* Checks */ orxASSERT((sstMemory.u32Flags & orxMEMORY_KU32_STATIC_FLAG_READY) == orxMEMORY_KU32_STATIC_FLAG_READY); #ifdef __orxPROFILER__ /* Valid? */ if(_pMem != NULL) { orxMEMORY_TYPE eMemType; size_t uMemoryChunkSize; /* Updates pointer */ _pMem = (orxU8 *)_pMem - sizeof(orxMEMORY_TYPE); /* Gets memory type from memory chunk tag */ eMemType = *(orxMEMORY_TYPE *)_pMem; /* Gets memory chunk size */ uMemoryChunkSize = dlmalloc_usable_size(_pMem); /* Updates memory tracker */ orxMemory_Track(eMemType, (orxU32)(uMemoryChunkSize - sizeof(orxMEMORY_TYPE)), orxFALSE); } #endif /* __orxPROFILER__ */ /* System call to free memory */ dlfree(_pMem); return; }
/** Allocates a portion of memory in the system and returns a pointer on it * @param[in] _u32Size size of the memory to allocate * @param[in] _eMemType Memory zone where data will be allocated * @return returns a pointer on the memory allocated, or orxNULL if an error has occurred */ void *orxFASTCALL orxMemory_Allocate(orxU32 _u32Size, orxMEMORY_TYPE _eMemType) { void *pResult; /* Checks */ orxASSERT((sstMemory.u32Flags & orxMEMORY_KU32_STATIC_FLAG_READY) == orxMEMORY_KU32_STATIC_FLAG_READY); orxASSERT(_eMemType < orxMEMORY_TYPE_NUMBER); #ifdef __orxPROFILER__ /* Allocates memory */ pResult = dlmalloc((size_t)(_u32Size + sizeof(orxMEMORY_TYPE))); /* Success? */ if(pResult != NULL) { size_t uMemoryChunkSize; /* Tags memory chunk */ *(orxMEMORY_TYPE *)pResult = _eMemType; /* Gets memory chunk size */ uMemoryChunkSize = dlmalloc_usable_size(pResult); /* Updates memory tracker */ orxMemory_Track(_eMemType, (orxU32)(uMemoryChunkSize - sizeof(orxMEMORY_TYPE)), orxTRUE); /* Updates result */ pResult = (orxU8 *)pResult + sizeof(orxMEMORY_TYPE); } #else /* __orxPROFILER__ */ /* Allocates memory */ pResult = dlmalloc((size_t)_u32Size); #endif /* __orxPROFILER__ */ /* Done! */ return pResult; }
size_t _swift_stdlib_malloc_size(const void *ptr) { return dlmalloc_usable_size(const_cast<void *>(ptr)); }
extern "C" size_t malloc_usable_size(void* mem) { return dlmalloc_usable_size(mem); }
size_t amemcheck_malloc_usable_size(void* mem) { return dlmalloc_usable_size(mem); }
// TODO: function name // TODO: macro, including res void _encounter_1(int nobreak, const char* name, DW o) { #define ENCOUNTER_STRING "\n\n\n\n==== *** ENCOUNTER ***\n\n==== encountered " int i; for(i=0; i<encounterList.n; i++) { if(encounterList.x[i] == o) { DLOG(ENCOUNTER_STRING "%lx in %s t=%i nobreak=%i", o, name, encounterList.t, nobreak); if(!nobreak && !--encounterList.t) { crash(); } } else if(encounterList.x[i] <= o && /*dlmalloc_usable_size(encounterList.x[i]) != 0 &&*/ o <= 2048 /*dlmalloc_usable_size(o)*/ + (DW)encounterList.x[i]) { DLOG(ENCOUNTER_STRING "%lx within %lx [%lx] in %s t=%i nobreak=%i", o, encounterList.x[i], (DW)dlmalloc_usable_size(encounterList.x[i]), name, encounterList.t, nobreak); if(!nobreak && !--encounterList.t) { crash(); } } } }