cleanup memory file
authorhgn <hgodden00@gmail.com>
Fri, 9 Jun 2023 17:07:37 +0000 (18:07 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 9 Jun 2023 17:07:37 +0000 (18:07 +0100)
vg_mem.h

index a69779ebadfd3441a1c49c1e51f096fa353d8340..f8d26d4e7775a4a17d777c537ea61dbd776c8105 100644 (file)
--- a/vg_mem.h
+++ b/vg_mem.h
@@ -63,6 +63,61 @@ struct vg_linear_allocator
 };
 #pragma pack(pop)
 
+VG_STATIC u32 vg_align8( u32 s );
+VG_STATIC u32 vg_align4( u32 s );
+
+/* allocate something from a linear allocator */
+__attribute__((warn_unused_result))
+VG_STATIC void *_vg_linear_alloc( void *buffer, u32 size, 
+                                  const char *constr_name );
+
+/* resize latest block of memory from linear */
+__attribute__((warn_unused_result))
+VG_STATIC void *vg_linear_resize( void *buffer, void *data, u32 newsize );
+
+/* its possible to delete just the last item */
+VG_STATIC void vg_linear_del( void *buffer, void *data );
+
+/* extend latest block of memory from linear */
+__attribute__((warn_unused_result))
+VG_STATIC void *_vg_linear_extend( void *buffer, void *data, u32 extra,
+                                   const char *constr_name );
+
+/* get the current usage of allocator */
+VG_STATIC u32 vg_linear_get_cur( void *buffer );
+
+/* get the capacity of allocator. */
+VG_STATIC u32 vg_linear_get_capacity( void *buffer );
+
+/* get the remaining size of the allocator */
+VG_STATIC u32 vg_linear_remaining( void *buffer );
+
+/* yeet all memory from linear allocator */
+VG_STATIC void vg_linear_clear( void *buffer );
+
+/* request all the memory we need in advance */
+VG_STATIC void vg_set_mem_quota( u32 size );
+
+/* essentially init() */
+VG_STATIC void vg_alloc_quota(void);
+
+/* print out tree of current memory used. only works with libc mode */
+VG_STATIC void vg_mem_log( void *lin_alloc, int depth, const char *name );
+
+#define VG_MEM_MCSTR(S) VG_MEM_MCSTR2(S)
+#define VG_MEM_MCSTR2(S) #S
+
+#define vg_linear_alloc(...) \
+   _vg_linear_alloc( __VA_ARGS__, __FILE__":"VG_MEM_MCSTR(__LINE__) )
+#define vg_linear_extend(...) \
+   _vg_linear_extend( __VA_ARGS__, __FILE__":"VG_MEM_MCSTR(__LINE__) )
+#define vg_create_linear_allocator(...) \
+   _vg_create_linear_allocator( __VA_ARGS__, __FILE__":"VG_MEM_MCSTR(__LINE__) )
+
+/* implementation
+ * ----------------------------------------
+ */
+
 VG_STATIC void vg_fatal_error( const char *fmt, ... );
 VG_STATIC void vg_error(const char *fmt, ...);
 VG_STATIC void vg_info(const char *fmt, ...);
@@ -403,15 +458,4 @@ VG_STATIC void vg_mem_log( void *lin_alloc, int depth, const char *name )
    }
 }
 
-#define VG_MEM_MCSTR(S) VG_MEM_MCSTR2(S)
-#define VG_MEM_MCSTR2(S) #S
-
-#define vg_linear_alloc(...) \
-   _vg_linear_alloc( __VA_ARGS__, __FILE__":"VG_MEM_MCSTR(__LINE__) )
-#define vg_linear_extend(...) \
-   _vg_linear_extend( __VA_ARGS__, __FILE__":"VG_MEM_MCSTR(__LINE__) )
-#define vg_create_linear_allocator(...) \
-   _vg_create_linear_allocator( __VA_ARGS__, __FILE__":"VG_MEM_MCSTR(__LINE__) )
-
-
 #endif /* VG_MEM_H */