mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-23 15:16:26 +01:00
mem management:avoid potential infinite allocation
This commit is contained in:
parent
a4b42445c1
commit
964687d1b4
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user