mem management:avoid potential infinite allocation

This commit is contained in:
augustin64 2023-05-19 17:43:56 +02:00
parent a4b42445c1
commit 964687d1b4
2 changed files with 2 additions and 4 deletions

View File

@ -136,8 +136,7 @@ void* allocate_memory(int nb_elements, size_t size, Memory* mem) {
//printf("Mémoire disponible: %ld. Nécessaire: %ld\n", mem->size - ((intptr_t)mem->cursor - (intptr_t)mem->start), nb_elements*size); //printf("Mémoire disponible: %ld. Nécessaire: %ld\n", mem->size - ((intptr_t)mem->cursor - (intptr_t)mem->start), nb_elements*size);
// Sinon on continue sur l'élément suivant de la liste // Sinon on continue sur l'élément suivant de la liste
if (!mem->next) { if (!mem->next) {
//! WARNING: May cause Infinite allocations when trying to allocate more than MEMORY_BLOCK size at once that is not naturally aligned (CUDA only) mem->next = create_memory_block(MEMORY_BLOCK < (nb_elements+1)*size ? (nb_elements+1)*size : MEMORY_BLOCK);
mem->next = create_memory_block(MEMORY_BLOCK < nb_elements*size ? nb_elements*size : MEMORY_BLOCK);
} }
return allocate_memory(nb_elements, size, mem->next); return allocate_memory(nb_elements, size, mem->next);
} }

View File

@ -136,8 +136,7 @@ void* allocate_memory(int nb_elements, size_t size, Memory* mem) {
//printf("Mémoire disponible: %ld. Nécessaire: %ld\n", mem->size - ((intptr_t)mem->cursor - (intptr_t)mem->start), nb_elements*size); //printf("Mémoire disponible: %ld. Nécessaire: %ld\n", mem->size - ((intptr_t)mem->cursor - (intptr_t)mem->start), nb_elements*size);
// Sinon on continue sur l'élément suivant de la liste // Sinon on continue sur l'élément suivant de la liste
if (!mem->next) { if (!mem->next) {
//! WARNING: May cause Infinite allocations when trying to allocate more than MEMORY_BLOCK size at once that is not naturally aligned (CUDA only) mem->next = create_memory_block(MEMORY_BLOCK < (nb_elements+1)*size ? (nb_elements+1)*size : MEMORY_BLOCK);
mem->next = create_memory_block(MEMORY_BLOCK < nb_elements*size ? nb_elements*size : MEMORY_BLOCK);
} }
return allocate_memory(nb_elements, size, mem->next); return allocate_memory(nb_elements, size, mem->next);
} }