mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[cpp] Fixed up Pool to not be dumb, added more stats to test harness.
This commit is contained in:
parent
4234b17ffa
commit
3cf3312180
@ -33,20 +33,23 @@
|
|||||||
|
|
||||||
void *Spine::TestSpineExtension::_alloc(size_t size, const char *file, int line) {
|
void *Spine::TestSpineExtension::_alloc(size_t size, const char *file, int line) {
|
||||||
void* result = DefaultSpineExtension::_alloc(size, file, line);
|
void* result = DefaultSpineExtension::_alloc(size, file, line);
|
||||||
allocated.push_back(Allocation(result, size, file, line));
|
_allocated.push_back(Allocation(result, size, file, line));
|
||||||
|
_allocations++;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Spine::TestSpineExtension::_calloc(size_t size, const char *file, int line) {
|
void *Spine::TestSpineExtension::_calloc(size_t size, const char *file, int line) {
|
||||||
void* result = DefaultSpineExtension::_calloc(size, file, line);
|
void* result = DefaultSpineExtension::_calloc(size, file, line);
|
||||||
allocated.push_back(Allocation(result, size, file, line));
|
_allocated.push_back(Allocation(result, size, file, line));
|
||||||
|
_allocations++;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Spine::TestSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) {
|
void *Spine::TestSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) {
|
||||||
void* result = DefaultSpineExtension::_realloc(ptr, size, file, line);
|
void* result = DefaultSpineExtension::_realloc(ptr, size, file, line);
|
||||||
|
_reallocations++;
|
||||||
|
|
||||||
for (std::vector<Allocation>::iterator it = allocated.begin(); it != allocated.end(); it++) {
|
for (std::vector<Allocation>::iterator it = _allocated.begin(); it != _allocated.end(); it++) {
|
||||||
if (it->address == ptr) {
|
if (it->address == ptr) {
|
||||||
it->address = result;
|
it->address = result;
|
||||||
it->size = size;
|
it->size = size;
|
||||||
@ -56,16 +59,17 @@ void *Spine::TestSpineExtension::_realloc(void *ptr, size_t size, const char *fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allocated.push_back(Allocation(result, size, file, line));
|
_allocated.push_back(Allocation(result, size, file, line));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spine::TestSpineExtension::_free(void *mem, const char *file, int line) {
|
void Spine::TestSpineExtension::_free(void *mem, const char *file, int line) {
|
||||||
|
|
||||||
for (std::vector<Allocation>::iterator it = allocated.begin(); it != allocated.end(); it++) {
|
for (std::vector<Allocation>::iterator it = _allocated.begin(); it != _allocated.end(); it++) {
|
||||||
if (it->address == mem) {
|
if (it->address == mem) {
|
||||||
DefaultSpineExtension::_free(mem, file, line);
|
DefaultSpineExtension::_free(mem, file, line);
|
||||||
allocated.erase(it);
|
_frees++;
|
||||||
|
_allocated.erase(it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,12 +79,13 @@ void Spine::TestSpineExtension::_free(void *mem, const char *file, int line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Spine::TestSpineExtension::reportLeaks() {
|
void Spine::TestSpineExtension::reportLeaks() {
|
||||||
for (std::vector<Allocation>::iterator it = allocated.begin(); it != allocated.end(); it++) {
|
for (std::vector<Allocation>::iterator it = _allocated.begin(); it != _allocated.end(); it++) {
|
||||||
printf("\"%s:%i (%zu bytes at %p)\n", it->fileName, it->line, it->size, it->address);
|
printf("\"%s:%i (%zu bytes at %p)\n", it->fileName, it->line, it->size, it->address);
|
||||||
}
|
}
|
||||||
if (allocated.empty()) printf("No leaks detected");
|
printf("allocations: %lu, reallocations: %lu, frees: %lu\n", _allocations, _reallocations, _frees);
|
||||||
|
if (_allocated.empty()) printf("No leaks detected");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spine::TestSpineExtension::clearAllocations() {
|
void Spine::TestSpineExtension::clearAllocations() {
|
||||||
allocated.resize(0);
|
_allocated.resize(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,10 @@ namespace Spine {
|
|||||||
virtual void _free(void* mem, const char* file, int line);
|
virtual void _free(void* mem, const char* file, int line);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Allocation> allocated;
|
std::vector<Allocation> _allocated;
|
||||||
|
size_t _allocations;
|
||||||
|
size_t _reallocations;
|
||||||
|
size_t _frees;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,9 +49,9 @@ namespace Spine {
|
|||||||
|
|
||||||
T* obtain() {
|
T* obtain() {
|
||||||
if (_objects.size() > 0) {
|
if (_objects.size() > 0) {
|
||||||
T** object = _objects.begin();
|
T** object = _objects.end();
|
||||||
T* ret = *object;
|
T* ret = *object;
|
||||||
_objects.removeAt(0);
|
_objects.removeAt(_objects.size() - 1);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user