DCEmulation

dreamcast development • homebrew software • hardware hacking • indie games • emulators • and more!
Back to main site
It is currently Sat Feb 24, 2018 5:19 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: MALLOC Garbage Collector
PostPosted: Wed Aug 23, 2017 8:35 am 
Offline
DCEmu Crazy Poster
DCEmu Crazy Poster

Joined: Tue Nov 01, 2011 5:30 pm
Posts: 26
Hello, i am using malloc and free..

exists a garbage collector to prevent mem fragmentation... ?

or a method to manage mem to best ?

_________________
Colombian Developers
http://coldev.sf.net
Dreamcast Dev:
https://sourceforge.net/projects/coldev/files/Dreamcast


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 23, 2017 8:50 am 
Offline
The Crabby Overlord
The Crabby Overlord
User avatar

Joined: Mon May 27, 2002 9:31 am
Posts: 5235
C and C++ do not have a garbage collector. Even if they did, this wouldn't solve fragmentation unless there was also some form of compaction, which is a very difficult task to accomplish in a language like C or C++ that runs on the bare metal (and not through something like a JVM or the .NET runtime on a PC).

The malloc implementation used by KallistiOS is generally pretty good about preventing large-scale fragmentation problems, but it (of course) is not perfect. Just make sure you actually free everything you allocate with malloc, and you should be fine (unless you request something that's too large, of course).


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 14, 2017 10:49 pm 
Offline
DCEmu Crazy Poster
DCEmu Crazy Poster

Joined: Tue Nov 01, 2011 5:30 pm
Posts: 26
hello , i need free mem...

+ i have mem problems

i call this in a function but (DC free mem is the same)

KOS_INIT_FLAGS(INIT_DEFAULT | INIT_MALLOCSTATS );

i call mm_init ();

but i have malloc crash errors..

how restart malloc , mem global restart.. what function.. ? not restart console, only restart kos malloc o manager system..



+ other question is possible pass params to arch_exec() function ?
how this .. arch_exec("hola.bin", "param1 param2");

+ question.. How get current directory path in kos ? get executable directory?


Thanks for your time..

_________________
Colombian Developers
http://coldev.sf.net
Dreamcast Dev:
https://sourceforge.net/projects/coldev/files/Dreamcast


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 14, 2017 11:30 pm 
Offline
The Crabby Overlord
The Crabby Overlord
User avatar

Joined: Mon May 27, 2002 9:31 am
Posts: 5235
You cannot reset the memory allocator once the program has started. Doing so would mess with all the allocations that the hardware-related code does on startup, for instance. No operating system that I'm aware of would ever allow such a thing during the execution of a program because it is a very bad idea.

KOS doesn't have any concept of arguments being passed to programs, nor does it have any concept of a path where the program is located. If you want to do something like that, you'll have to implement it on your own (by finding an unused place in memory to store them, or something).

Getting the current working directory can be done in the normal C way with the POSIX standard getcwd() function, or through the KOS-specific function fs_getwd().


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 16, 2017 9:59 am 
Offline
DCEmu Crazy Poster
DCEmu Crazy Poster

Joined: Tue Nov 01, 2011 5:30 pm
Posts: 26
thanks for reply...

i use function arch_exec, to free mem...

but i have a errror



===== the DC exec.elf process ======
Error: mapped file /cd/OTHER/1ST_READ.BIN .. DC exec call failed
fase 5
arch: shutting down kernel
Except in block A0B3A85 | CF8AF28
Except in block A0B3A85 | CF8AF28
maple: final stats -- device count = 2, vbl_cntr = 6, dma_cntr = 6
Except in block A0B6891 | CF8B6A8
Except in block A0B6891 | CF8B6A8
Except in block A0B6C22 | CF8B9A8
Except in block A0B6C22 | CF8B9A8
VREG = 03 ARMRST 01
vid_set_mode: 640x480IL NTSC
VREG = 03 ARMRST 01
TI , invalidating *TLB
not implemented opcode : 8C00 : unknown opcode @ 8C00E0A2
Press Any key to continue



executable requires any format to use? please help me...



my source code ....



//===========================================

const char *cadena= string_get( params[1] );

file_t f;
void *subelf;

/* Print a hello */
printf("===== the DC exec.elf process ====== \n");

/* Map the sub-elf */
f = fs_open(cadena, O_RDONLY);
if (f)
{
subelf = fs_mmap(f);
if (subelf)
{
/* Tell exec to replace us */
printf("sub.bin mapped at %08x, jumping to it! \n", subelf);
arch_exec(subelf, fs_total(f));
}
else
printf("Error: mapped file %s .. \n",cadena);
}
else
printf("File %s dnt exists \n",cadena);

/* Shouldn't get here */
printf( "DC exec call failed \n");

string_discard( params[1] ) ;
//===========================================


thanks for your help

_________________
Colombian Developers
http://coldev.sf.net
Dreamcast Dev:
https://sourceforge.net/projects/coldev/files/Dreamcast


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 16, 2017 6:06 pm 
Offline
The Crabby Overlord
The Crabby Overlord
User avatar

Joined: Mon May 27, 2002 9:31 am
Posts: 5235
fs_mmap() does not do what you're expecting it to do for most filesystems, including iso9660. You need to open the file, find the file size yourself (fs_total() will work here), read it in, and then you should be able to jump to it.

arch_exec() expects your binary you load to just be a simple raw binary and it cannot be scrambled (unless you unscramble it yourself before calling arch_exec()).


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 16, 2017 7:04 pm 
Offline
DCEmu Crazy Poster
DCEmu Crazy Poster

Joined: Tue Nov 01, 2011 5:30 pm
Posts: 26
Thank you again.. God Bless You..

1. compile elf...
2. use objcopy
sh-elf-objcopy -R .stack -O binary bennudreamcast.exe 1ST_READ.BIN


3. the code...

//=========================
void *blob;
ssize_t length = fs_load(cadena, &blob);
if (length > 0)
{
printf ("Executing binary %s \n",cadena);
arch_exec(blob, length);
}
else
printf ("Error: Execute binary %s \n",cadena);



//=========================

_________________
Colombian Developers
http://coldev.sf.net
Dreamcast Dev:
https://sourceforge.net/projects/coldev/files/Dreamcast


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 17, 2017 2:03 pm 
Offline
DCEmu Crazy Poster
DCEmu Crazy Poster

Joined: Tue Nov 01, 2011 5:30 pm
Posts: 26
Dnt work ... restart and load main executable again



Relocated dynarec blocks: 1235 KB before, 1231 KB new, 3915 bytes diff, 0.31%
Executing binary /cd/GAME4/1ST_READ.BIN
arch: shutting down kernel
Except in block C12F135 | F0FF248
Except in block C12F135 | F0FF248
maple: final stats -- device count = 2, vbl_cntr = 5609, dma_cntr = 5609
Except in block C131A6B | F100088
Except in block C131A6B | F100088
Except in block C131DFC | F100268
Except in block C131DFC | F100268
VREG = 03 ARMRST 01
vid_set_mode: 640x480IL NTSC
VREG = 03 ARMRST 01
i-cache invalidation requested! (11 total)
Reseting Dynarec Cache on ICI due to manual block count
Reseting Dynarec Cache...

_________________
Colombian Developers
http://coldev.sf.net
Dreamcast Dev:
https://sourceforge.net/projects/coldev/files/Dreamcast


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group