This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit ba789305742ef56eba7f777e6e66c8ca20d67e38 Author: Matteo Golin <[email protected]> AuthorDate: Fri Oct 16 16:31:30 2026 -0400 games/NXDoom: Implement static backing of z_zone The `z_zone` implementation now allows for a static array to back the memory allocator for devices where heap allocation isn't feasible. Signed-off-by: Matteo Golin <[email protected]> --- games/NXDoom/Kconfig | 12 ++++++++ games/NXDoom/src/i_system.c | 67 ++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/games/NXDoom/Kconfig b/games/NXDoom/Kconfig index b1fe44ff8..bdbf4397e 100644 --- a/games/NXDoom/Kconfig +++ b/games/NXDoom/Kconfig @@ -284,4 +284,16 @@ choice # Memory allocation implementaiton endchoice # Memory allocation implementaiton +if GAMES_NXDOOM_ALLOC_ZZONE + +config GAMES_NXDOOM_ALLOC_ZZONESTATIC + bool "Use static z_zone" + default n + ---help--- + When using the `z_zone` allocator, use static memory to back the + allocations instead of getting the initial memory from the heap + using `malloc()`. + +endif # GAMES_NXDOOM_ALLOC_ZZONE + endif # GAMES_NXDOOM diff --git a/games/NXDoom/src/i_system.c b/games/NXDoom/src/i_system.c index a13fbd36c..457e51168 100644 --- a/games/NXDoom/src/i_system.c +++ b/games/NXDoom/src/i_system.c @@ -118,6 +118,15 @@ static unsigned char mem_dump_custom[DOS_MEM_DUMP_SIZE]; static const unsigned char *dos_mem_dump = mem_dump_dos622; +/* TODO: Maybe here we can choose to allocate single or double RAM size + * memory (same as in `i_zone_base` auto allocation logic) based on pointer + * size, too. + */ + +#ifdef CONFIG_GAMES_NXDOOM_ALLOC_ZZONESTATIC +static byte g_zonemem[MIN_RAM * 1024 * 1024]; +#endif /* CONFIG_GAMES_NXDOOM_ALLOC_ZZONESTATIC */ + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -127,14 +136,13 @@ static const unsigned char *dos_mem_dump = mem_dump_dos622; * works. */ +#ifndef CONFIG_GAMES_NXDOOM_ALLOC_ZZONESTATIC static byte *auto_alloc_memory(int *size, int default_ram, int min_ram) { byte *zonemem; /* Allocate the zone memory. This loop tries progressively smaller * zone sizes until a size is found that can be allocated. - * If we used the -mb command line parameter, only the parameter - * provided is accepted. */ zonemem = NULL; @@ -166,6 +174,7 @@ static byte *auto_alloc_memory(int *size, int default_ram, int min_ram) return zonemem; } +#endif /* CONFIG_GAMES_NXDOOM_ALLOC_ZZONESTATIC */ /**************************************************************************** * Public Functions @@ -192,46 +201,34 @@ void i_tactile(int on, int off, int total) byte *i_zone_base(int *size) { byte *zonemem; - int min_ram; - int default_ram; - int p; - /* @category obscure - * @arg <mb> - * - * Specify the heap size, in MiB. + /* Because of the 8-byte pointer size in a 64-bit build, the default + * heap size (16 MiB) is insufficient compared to a 32-bit build. For + * example, the Alien Vendetta avm62402.lmp demo completes successfully + * on a 32-bit build, but terminates with an out of memory error on a + * 64-bit build. Therefore, to maintain consistency with a 32-bit + * build, the heap size should be increased. */ - p = m_check_parm_with_args("-mb", 1); + /* Determine pointer size */ - if (p > 0) - { - default_ram = atoi(myargv[p + 1]); - min_ram = default_ram; - } - else - { - /* Because of the 8-byte pointer size in a 64-bit build, the default - * heap size (16 MiB) is insufficient compared to a 32-bit build. For - * example, the Alien Vendetta avm62402.lmp demo completes successfully - * on a 32-bit build, but terminates with an out of memory error on a - * 64-bit build. Therefore, to maintain consistency with a 32-bit - * build, the heap size should be increased. - */ + static_assert(sizeof(void *) == sizeof(uintptr_t), + "Cannot determine pointer size."); - if (sizeof(void *) == 8) - { - default_ram = DEFAULT_RAM * 2; - } - else - { - default_ram = DEFAULT_RAM; - } +#ifdef CONFIG_GAMES_NXDOOM_ALLOC_ZZONESTATIC + /* Static backing memory */ - min_ram = MIN_RAM; - } + zonemem = g_zonemem; + *size = sizeof(g_zonemem); +#else + /* We're using heap allocation implementation, malloc memory */ - zonemem = auto_alloc_memory(size, default_ram, min_ram); +#if UINTPTR_MAX == 0xffffffffffffffffu + zonemem = auto_alloc_memory(size, DEFAULT_RAM * 2, MIN_RAM); +#else + zonemem = auto_alloc_memory(size, DEFAULT_RAM, MIN_RAM); +#endif /* UINTPTR_MAX */ +#endif /* CONFIG_GAMES_NXDOOM_ALLOC_ZZONESTATIC */ printf("zone memory: %p, %x allocated for zone\n", zonemem, *size);
