comparison dowa/dowa.h @ 52:636eab07809d

Fixed dowa memory problems. Add few more utility functions.
author June Park <parkjune1995@gmail.com>
date Fri, 19 Dec 2025 13:30:30 -0800
parents 84672efec192
children e06bc03d9618
comparison
equal deleted inserted replaced
51:68fa88ac73fe 52:636eab07809d
52 extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size); 52 extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size);
53 /* Destroys the arena and frees its underlying memory block.*/ 53 /* Destroys the arena and frees its underlying memory block.*/
54 extern void Dowa_Arena_Destroy(Dowa_PArena arena); 54 extern void Dowa_Arena_Destroy(Dowa_PArena arena);
55 /* Strdup but saves within the arena */ 55 /* Strdup but saves within the arena */
56 extern void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size); 56 extern void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size);
57 /* Resets the arena offset to 0, allowing reuse without freeing */
58 extern void Dowa_Arena_Reset(Dowa_PArena p_arena);
59 /* Returns the current number of bytes allocated in the arena */
60 extern size_t Dowa_Arena_Get_Used(Dowa_PArena p_arena);
61 /* Returns the remaining capacity in bytes */
62 extern size_t Dowa_Arena_Get_Remaining(Dowa_PArena p_arena);
57 63
58 64
59 // --- HashMap --- // 65 // --- HashMap --- //
60 typedef enum { 66 typedef enum {
61 DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer 67 DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer
95 extern int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); 101 extern int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type);
96 /* Inserts a value pointer into the hashmap under the specified key without copying data. The caller retains ownership of the pointer. Returns the entry index, or -1 on failure. */ 102 /* Inserts a value pointer into the hashmap under the specified key without copying data. The caller retains ownership of the pointer. Returns the entry index, or -1 on failure. */
97 extern int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); 103 extern int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type);
98 /* Removes the entry with the specified key from the hashmap and frees its data if owned. */ 104 /* Removes the entry with the specified key from the hashmap and frees its data if owned. */
99 extern void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key); 105 extern void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key);
106 /* Returns TRUE if the key exists in the hashmap, FALSE otherwise. */
107 extern boolean Dowa_HashMap_Has_Key(Dowa_PHashMap p_hash_map, const char *key);
108 /* Removes all entries from the hashmap without destroying it. */
109 extern void Dowa_HashMap_Clear(Dowa_PHashMap p_hash_map);
110 /* Returns the number of entries currently in the hashmap. */
111 extern uint32 Dowa_HashMap_Get_Count(Dowa_PHashMap p_hash_map);
100 112
101 // --- Utility Functions --- // 113 // --- Utility Functions --- //
102 /* Prints all entries in the hashmap to stdout for debugging purposes. */ 114 /* Prints all entries in the hashmap to stdout for debugging purposes. */
103 extern void Dowa_HashMap_Print(Dowa_PHashMap map); 115 extern void Dowa_HashMap_Print(Dowa_PHashMap map);
104 /* Loads all files from the specified folder into the hashmap. Uses file names as keys and file contents as values. Returns 0 on success, or -1 on failure. */ 116 /* Loads all files from the specified folder into the hashmap. Uses file names as keys and file contents as values. Returns 0 on success, or -1 on failure. */