Removed temporary memory from the API
It was intended to make the API easier to use, but various automatic garbage collection all had flaws, and making the application periodically clean up temporary memory added cognitive load to using the API, and in many cases was it was difficult to restructure threaded code to handle this. So, we're largely going back to the original system, where the API returns allocated results and you free them. In addition, to solve the problems we originally wanted temporary memory for: * Short strings with a finite count, like device names, get stored in a per-thread string pool. * Events continue to use temporary memory internally, which is cleaned up on the next event processing cycle.
This commit is contained in:
@@ -175,67 +175,6 @@ static int events_addDelEventWatchWithUserdata(void *arg)
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and validates temporary event memory
|
||||
*/
|
||||
static int events_temporaryMemory(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
void *mem, *claimed, *tmp;
|
||||
SDL_bool found;
|
||||
|
||||
{
|
||||
/* Create and claim event memory */
|
||||
mem = SDL_AllocateTemporaryMemory(1);
|
||||
SDLTest_AssertCheck(mem != NULL, "SDL_AllocateTemporaryMemory()");
|
||||
*(char *)mem = '1';
|
||||
|
||||
claimed = SDL_ClaimTemporaryMemory(mem);
|
||||
SDLTest_AssertCheck(claimed != NULL, "SDL_ClaimTemporaryMemory() returned a valid pointer");
|
||||
|
||||
/* Verify that we can't claim it again */
|
||||
tmp = SDL_ClaimTemporaryMemory(mem);
|
||||
SDLTest_AssertCheck(tmp == NULL, "SDL_ClaimTemporaryMemory() can't claim memory twice");
|
||||
|
||||
/* Clean up */
|
||||
SDL_free(claimed);
|
||||
}
|
||||
|
||||
{
|
||||
/* Create event memory and queue it */
|
||||
mem = SDL_AllocateTemporaryMemory(1);
|
||||
SDLTest_AssertCheck(mem != NULL, "SDL_AllocateTemporaryMemory()");
|
||||
*(char *)mem = '2';
|
||||
|
||||
SDL_zero(event);
|
||||
event.type = SDL_EVENT_USER;
|
||||
event.user.data1 = mem;
|
||||
SDL_PushEvent(&event);
|
||||
|
||||
/* Verify that we can't claim the memory once it's on the queue */
|
||||
claimed = SDL_ClaimTemporaryMemory(mem);
|
||||
SDLTest_AssertCheck(claimed == NULL, "SDL_ClaimTemporaryMemory() can't claim memory on the event queue");
|
||||
|
||||
/* Get the event and verify the memory is valid */
|
||||
found = SDL_FALSE;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_EVENT_USER && event.user.data1 == mem) {
|
||||
found = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(found, "SDL_PollEvent() returned queued event");
|
||||
|
||||
/* Verify that we can claim the memory now that we've dequeued it */
|
||||
claimed = SDL_ClaimTemporaryMemory(mem);
|
||||
SDLTest_AssertCheck(claimed != NULL, "SDL_ClaimTemporaryMemory() can claim memory after dequeuing event");
|
||||
|
||||
/* Clean up */
|
||||
SDL_free(claimed);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Events test cases */
|
||||
@@ -251,13 +190,9 @@ static const SDLTest_TestCaseReference eventsTest3 = {
|
||||
(SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference eventsTestTemporaryMemory = {
|
||||
(SDLTest_TestCaseFp)events_temporaryMemory, "events_temporaryMemory", "Creates and validates temporary event memory", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Events test cases */
|
||||
static const SDLTest_TestCaseReference *eventsTests[] = {
|
||||
&eventsTest1, &eventsTest2, &eventsTest3, &eventsTestTemporaryMemory, NULL
|
||||
&eventsTest1, &eventsTest2, &eventsTest3, NULL
|
||||
};
|
||||
|
||||
/* Events test suite (global) */
|
||||
|
||||
Reference in New Issue
Block a user