Jo Engine  2024.04.28
Jo Sega Saturn Engine
malloc.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2024, Johannes Fetz (johannesfetz@gmail.com)
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the Johannes Fetz nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
35 #ifndef __JO_MALLOC_H__
36 # define __JO_MALLOC_H__
37 
42 #define JO_MALLOC_MAX_MEMORY_ZONE (9)
43 
45 typedef enum
46 {
54 
70 typedef enum
71 {
79 
85 void *jo_malloc_with_behaviour(unsigned int n, const jo_malloc_behaviour behaviour);
86 
91 static __jo_force_inline void *jo_malloc(unsigned int n)
92 {
94 }
95 
99 void jo_free(const void * const p);
100 
105 
111 void jo_add_memory_zone(unsigned char *ptr, const unsigned int size_in_bytes);
112 
113 #ifdef JO_COMPILE_WITH_RAM_CARD_SUPPORT
114 
118 static __jo_force_inline jo_extended_ram_cartridge_type jo_get_extended_ram_cartridge_type(void)
119 {
120  return *((char *)0x24FFFFFF) == 0x5a ? CART_8MBits : *((char *)0x24FFFFFF) == 0x5c ? CART_32MBits : CART_NONE;
121 }
122 
123 #endif
124 
125 #ifdef JO_DEBUG
126 
132 
138 
139 #endif
140 
141 #endif /* !__JO_MALLOC_H__ */
142 
143 /*
144 ** END OF FILE
145 */
jo_reduce_memory_fragmentation
void jo_reduce_memory_fragmentation(void)
Reduce memory fragmentation for faster memory allocation.
JO_MALLOC_TRY_REUSE_BLOCK
@ JO_MALLOC_TRY_REUSE_BLOCK
A little bit slower but reduce memory fragmentation.
Definition: malloc.h:75
CART_8MBits
@ CART_8MBits
1 Mb cartridge
Definition: malloc.h:50
JO_FAST_ALLOCATION
@ JO_FAST_ALLOCATION
Default behaviour.
Definition: malloc.h:73
jo_malloc_behaviour
jo_malloc_behaviour
Malloc behaviour JO_MALLOC_TRY_REUSE_SAME_BLOCK_SIZE | ^ | | Speed efficiency | | V | JO_MALLOC_TRY_R...
Definition: malloc.h:71
jo_extended_ram_cartridge_type
jo_extended_ram_cartridge_type
Extended RAM cartridge type.
Definition: malloc.h:46
jo_malloc
static __jo_force_inline void * jo_malloc(unsigned int n)
dynamic memory allocator
Definition: malloc.h:91
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: types.h:39
jo_add_memory_zone
void jo_add_memory_zone(unsigned char *ptr, const unsigned int size_in_bytes)
Register a memory segment for jo_malloc() usage.
jo_malloc_with_behaviour
void * jo_malloc_with_behaviour(unsigned int n, const jo_malloc_behaviour behaviour)
dynamic memory allocator with specific behaviour
jo_memory_usage_percent
int jo_memory_usage_percent(void)
Get memory usage percent.
jo_free
void jo_free(const void *const p)
function frees the memory space pointed to by p
JO_MALLOC_TRY_REUSE_SAME_BLOCK_SIZE
@ JO_MALLOC_TRY_REUSE_SAME_BLOCK_SIZE
A little bit slower than JO_MALLOC_TRY_REUSE_BLOCK but reduce memory usage.
Definition: malloc.h:77
CART_NONE
@ CART_NONE
No cartridge.
Definition: malloc.h:48
jo_memory_fragmentation
int jo_memory_fragmentation(void)
Get memory fragmentation (Number of fragment in memory)
CART_32MBits
@ CART_32MBits
4 Mb cartridge
Definition: malloc.h:52