SDL  2.0
SDL_test_memory.h File Reference
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_test_memory.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int SDLTest_TrackAllocations ()
 Start tracking SDL memory allocations.
void SDLTest_LogAllocations ()
 Print a log of any outstanding allocations.

Detailed Description

Include file for SDL test framework.

This code is a part of the SDL2_test library, not the main SDL library.

Definition in file SDL_test_memory.h.

Function Documentation

void SDLTest_LogAllocations ( )

Print a log of any outstanding allocations.

Note
This can be called after SDL_Quit()

Definition at line 222 of file SDL_test_memory.c.

References ADD_LINE, SDL_tracked_allocation::next, NULL, SDL_arraysize, SDL_Log, SDL_malloc_orig, SDL_PRIx64, SDL_snprintf, SDL_strlcpy, SDL_tracked_allocation::size, SDL_tracked_allocation::stack, and SDL_tracked_allocation::stack_names.

Referenced by SDLTest_CommonQuit().

{
char *message = NULL;
size_t message_size = 0;
char line[128], *tmp;
int index, count, stack_index;
Uint64 total_allocated;
return;
}
#define ADD_LINE() \
message_size += (SDL_strlen(line) + 1); \
tmp = (char *)SDL_realloc_orig(message, message_size); \
if (!tmp) { \
return; \
} \
message = tmp; \
SDL_strlcat(message, line, message_size)
SDL_strlcpy(line, "Memory allocations:\n", sizeof(line));
SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof(line));
count = 0;
total_allocated = 0;
for (index = 0; index < SDL_arraysize(s_tracked_allocations); ++index) {
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
SDL_snprintf(line, sizeof(line), "Allocation %d: %d bytes\n", count, (int)entry->size);
/* Start at stack index 1 to skip our tracking functions */
for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) {
if (!entry->stack[stack_index]) {
break;
}
SDL_snprintf(line, sizeof(line), "\t0x%"SDL_PRIx64": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
}
total_allocated += entry->size;
++count;
}
}
SDL_snprintf(line, sizeof(line), "Total: %.2f Kb in %d allocations\n", (float)total_allocated / 1024, count);
#undef ADD_LINE
SDL_Log("%s", message);
}
int SDLTest_TrackAllocations ( )