12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #include <stdlib.h>
- #include <string.h>
- #include "RecastAlloc.h"
- static void *rcAllocDefault(int size, rcAllocHint)
- {
- return malloc(size);
- }
- static void rcFreeDefault(void *ptr)
- {
- free(ptr);
- }
- static rcAllocFunc* sRecastAllocFunc = rcAllocDefault;
- static rcFreeFunc* sRecastFreeFunc = rcFreeDefault;
- void rcAllocSetCustom(rcAllocFunc *allocFunc, rcFreeFunc *freeFunc)
- {
- sRecastAllocFunc = allocFunc ? allocFunc : rcAllocDefault;
- sRecastFreeFunc = freeFunc ? freeFunc : rcFreeDefault;
- }
- void* rcAlloc(int size, rcAllocHint hint)
- {
- return sRecastAllocFunc(size, hint);
- }
- void rcFree(void* ptr)
- {
- if (ptr)
- sRecastFreeFunc(ptr);
- }
- void rcIntArray::resize(int n)
- {
- if (n > m_cap)
- {
- if (!m_cap) m_cap = n;
- while (m_cap < n) m_cap *= 2;
- int* newData = (int*)rcAlloc(m_cap*sizeof(int), RC_ALLOC_TEMP);
- if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(int));
- rcFree(m_data);
- m_data = newData;
- }
- m_size = n;
- }
|