Merge from subtype branch.
[cacao.git] / src / mm / memory.h
index 300677645bbd0dd424fa657684bc56b535d0066e..ec6393f19f8a4ac959748a64750ca26a7cae8c89 100644 (file)
 #ifndef _MEMORY_H
 #define _MEMORY_H
 
-
 #include "config.h"
 
-#include <string.h>
+#include <stdint.h>
 
-#include "vm/types.h"
 
-#include "mm/codememory.h"
-#include "mm/dumpmemory.h"
+// Align the size of memory allocations to this size.
+#define ALIGNSIZE 8
+#define MEMORY_ALIGN(pos,size) ((((pos) + (size) - 1) / (size)) * (size))
 
 
-/* constants for ENABLE_MEMCHECK **********************************************/
+// Constants for ENABLE_MEMCHECK.
 
 #if defined(ENABLE_MEMCHECK)
 #define MEMORY_CANARY_SIZE          16
 #define MEMORY_CANARY_FIRST_BYTE    0xca
 #define MEMORY_CLEAR_BYTE           0xa5
-#endif /* defined(ENABLE_MEMCHECK) */
-
+#endif
 
-/* internal includes **********************************************************/
 
-#include "mm/gc-common.h"
+// Includes.
+#include "mm/codememory.h"
+#include "mm/dumpmemory.hpp"
+#include "mm/gc.hpp"
 
 
 /* 
@@ -63,15 +63,6 @@ There are two possible choices for allocating memory:
                        mem_realloc ... change size of a memory block (position may change)
                        mem_usage ..... amount of allocated memory
 
-
-       2.   explicit allocating, automatic deallocating
-       
-                       dump_alloc .... allocate a memory block in the dump area
-                       dump_realloc .. change size of a memory block (position may change)
-                       dump_size ..... marks the current top of dump
-                       dump_release .. free all memory requested after the mark
-                                       
-       
 There are some useful macros:
 
        NEW (type) ....... allocate memory for an element of type `type`
@@ -82,11 +73,6 @@ There are some useful macros:
        
        MREALLOC (ptr,type,num1,num2) .. enlarge the array to size num2
                                         
-These macros do the same except they operate on the dump area:
-       
-       DNEW,  DMNEW, DMREALLOC   (there is no DFREE)
-
-
 -------------------------------------------------------------------------------
 
 Some more macros:
@@ -102,9 +88,8 @@ Some more macros:
 
 */
 
-#define MEMORY_ALIGN(pos,size) ((((pos) + (size) - 1) / (size)) * (size))
 #define PADDING(pos,size)     (MEMORY_ALIGN((pos),(size)) - (pos))
-#define OFFSET(s,el)          ((s4) ((ptrint) &(((s*) 0)->el)))
+#define OFFSET(s,el)          ((int32_t) ((ptrint) &(((s*) 0)->el)))
 
 
 #define NEW(type)             ((type *) mem_alloc(sizeof(type)))
@@ -141,23 +126,31 @@ Some more macros:
 
 /* function prototypes ********************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 bool  memory_init(void);
 
 void  memory_mprotect(void *addr, size_t len, int prot);
 
 void *memory_checked_alloc(size_t size);
 
-void *memory_cnew(s4 size);
-void  memory_cfree(void *p, s4 size);
+void *memory_cnew(int32_t size);
+void  memory_cfree(void *p, int32_t size);
 
-void *mem_alloc(s4 size);
-void  mem_free(void *m, s4 size);
-void *mem_realloc(void *src, s4 len1, s4 len2);
+void *mem_alloc(int32_t size);
+void  mem_free(void *m, int32_t size);
+void *mem_realloc(void *src, int32_t len1, int32_t len2);
 
 #if defined(ENABLE_THREADS)
 bool  memory_start_thread(void);
 #endif
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _MEMORY_H */