Compare commits

..

No commits in common. "693fa06e816d47e8fc57f53a61b7adb3f5de2040" and "bba9be1c9c6d50cb38e6565488e4dab2b91fe138" have entirely different histories.

3 changed files with 6 additions and 57 deletions

View file

@ -24,15 +24,10 @@
#define HALLOCY_ALLOCATOR
#include <stddef.h>
#include <stdbool.h>
#include "../Utils/Error.h"
void *hallocy_allocate(size_t size, bool zero_memory);
static inline void *hallocy_malloc(size_t size) { return hallocy_allocate(size, false); }
static inline void *hallocy_calloc(size_t size, size_t count) { return hallocy_allocate(size * count, true); }
void *hallocy_realloc(void *memory_pointer, size_t size);
void *hallocy_malloc(size_t size);
HallocyError hallocy_free(void *pointer);
#endif

View file

@ -21,7 +21,8 @@
* -----------------------------------------------------------------------------
*/
#include "../../Include/Hallocy/Core/Allocator.h"
#include "../../Include/Hallocy/Core/Memory.h"
#include <stdbool.h>
#if defined(_WIN32)
#include <windows.h>
@ -69,7 +70,7 @@ static BOOL CALLBACK hallocy_initialize_mutex(PINIT_ONCE init_once, PVOID parame
}
#endif
void *hallocy_allocate(size_t size, bool zero_memory) {
void *hallocy_malloc(size_t size) {
if (page_size == 0) {
#if defined(_WIN32)
SYSTEM_INFO system_info;
@ -101,10 +102,6 @@ void *hallocy_allocate(size_t size, bool zero_memory) {
}
memory_pointer->next = NULL;
if (zero_memory) {
hallocy_set_memory(memory_pointer + 1, 0, aligned_size - sizeof(HallocyMemoryHeader));
}
return (void*)(memory_pointer + 1);
}
@ -117,12 +114,7 @@ void *hallocy_allocate(size_t size, bool zero_memory) {
hallocy_heap = GetProcessHeap();
}
if (zero_memory) {
memory_pointer = HeapAlloc(hallocy_heap, HEAP_ZERO_MEMORY, aligned_size);
} else {
memory_pointer = HeapAlloc(hallocy_heap, 0, aligned_size);
}
memory_pointer = HeapAlloc(hallocy_heap, 0, aligned_size);
if (memory_pointer == NULL) {
return NULL;
}
@ -170,10 +162,6 @@ void *hallocy_allocate(size_t size, bool zero_memory) {
#endif
memory_pointer->next = NULL;
if (zero_memory) {
hallocy_set_memory(memory_pointer + 1, 0, aligned_size - sizeof(HallocyMemoryHeader));
}
return (void*)(memory_pointer + 1);
}
@ -186,12 +174,7 @@ void *hallocy_allocate(size_t size, bool zero_memory) {
hallocy_heap = GetProcessHeap();
}
if (zero_memory) {
memory_pointer = HeapAlloc(hallocy_heap, HEAP_ZERO_MEMORY, aligned_size);
} else {
memory_pointer = HeapAlloc(hallocy_heap, 0, aligned_size);
}
memory_pointer = HeapAlloc(hallocy_heap, 0, aligned_size);
if (memory_pointer == NULL) {
return NULL;
}
@ -229,28 +212,6 @@ void *hallocy_allocate(size_t size, bool zero_memory) {
return (void*)(memory_pointer + 1);
}
void *hallocy_realloc(void *memory_pointer, size_t size) {
if (memory_pointer == NULL) {
return hallocy_allocate(size, false);
}
if (size == 0) {
hallocy_free(memory_pointer);
return NULL;
}
HallocyMemoryHeader *memory_header = ((HallocyMemoryHeader*)memory_pointer) - 1;
if (memory_header->size - sizeof(HallocyMemoryHeader) >= size) {
return memory_pointer;
}
void *new_memory = hallocy_allocate(size, false);
hallocy_copy_memory(new_memory, memory_pointer, memory_header->size);
hallocy_free(memory_pointer);
return new_memory;
}
HallocyError hallocy_free(void *pointer) {
if (pointer == NULL) {
return HALLOCY_ERROR_INVALID_POINTER;

View file

@ -70,13 +70,6 @@
printf("text_copy_copy and text_copy are equal\n");
}
text_copy_copy = (char*)hallocy_realloc(text_copy_copy, 40);
hallocy_set_memory(text_copy_copy + 35, 'q', 4);
text_copy_copy[39] = '\0';
printf("%s\n", text_copy_copy);
hallocy_free(text_copy_copy);
hallocy_free(text_copy);
hallocy_free(text);