Exemple #1
0
static void bkfree(fz_memorycontext *mem, void *p) {
	AllocMapIt it = alloc_allocs.find(p);
	if (it != alloc_allocs.end()) {
		alloc_current -= (*it).second;
		alloc_allocs.erase(it);
	}
	++alloc_frees;
	free(p);
}
Exemple #2
0
static void bkfree_all() {
	//printf("bkfree_all - %d\n", (int)alloc_current);
	AllocMapIt it = alloc_allocs.begin();
	if (it != alloc_allocs.end()) {
		free((*it).first);
		++it;
	}
	alloc_current = 0;
	alloc_allocs.clear();
}
Exemple #3
0
static void *bkrealloc(fz_memorycontext *mem, void *p, int n) {
	++alloc_reallocs;
	alloc_realloc_size += n;
	alloc_large_realloc = alloc_large_realloc < n ? n : alloc_large_realloc;
	AllocMapIt it = alloc_allocs.find(p);
	if (it != alloc_allocs.end()) {
		alloc_current -= (*it).second;
		alloc_allocs.erase(it);
	}
	void* r = realloc(p, n);
	alloc_allocs[r] = n;
	alloc_current += n;
	return r;
}
Exemple #4
0
static void reset_allocs() {
	alloc_mallocs = 0;
	alloc_malloc_size = 0;
	alloc_frees = 0;
	alloc_reallocs = 0;
	alloc_realloc_size = 0;
	alloc_large_realloc = 0;
	alloc_current = 0;
	alloc_allocs.clear();
}
Exemple #5
0
void NF_delete(void* ptr)
{
	//Unless allocation tracking is disabled, remove tracked pointer
	{
		lock_guard<recursive_mutex> memoryLock(memoryMutex);
		if (!allocDisabled)
			allocMap.erase(ptr);
	}
	//Free the pointer
	free(ptr);
}
Exemple #6
0
void* operator new[](unsigned int size, const char* sourceFile, const char *funcName, unsigned int lineNum)
{
	//Allocate memory for pointer
	void* temp = malloc(size);
	//Unless allocation tracking is disabled, track allocated memory.
	{
		lock_guard<recursive_mutex> memoryLock(memoryMutex);
		if (!allocDisabled)
			allocMap.map(AllocData{ temp, sourceFile, funcName, lineNum });
	}
	//Return pointer
	return temp;
}
Exemple #7
0
string getAllocs()
{
	lock_guard<recursive_mutex> memoryLock(memoryMutex);
	//If we're running without allocation tracking, don't return anything.
	if (allocDisabled == true)
		return string();
	//Allocate memory to hold results
	char temp[5000];
	//Disable memory allocation tracking within the block
	allocDisabled = true;
	{
		strcpy(temp, allocMap.getAllocData().substr(0, 4999).c_str());
	}
	//Re-enable allocation tracking
	allocDisabled = false;
	//Allocate a string and return the results.
	return string(temp);
}