Original Post

Did anyone get malloc/free working with gccVB? I got inspired to get back to some vb dev again 🙂 but I get these compiler errors:

/usr/local/v810/bin/ld: warning: no memory region specified for section `.sdata'

/usr/local/v810/lib/libc.a(malloc.o): In function `malloc':
/home/Dan/vb_v810_gcc_03/newlib_build/v810/newlib/libc/stdlib/../../../../../new
lib-1.10.0/newlib/libc/stdlib/malloc.c:194: could not locate special linker symb
ol __gp
/usr/local/v810/lib/libc.a(malloc.o): In function `free':
/home/Dan/vb_v810_gcc_03/newlib_build/v810/newlib/libc/stdlib/../../../../../new
lib-1.10.0/newlib/libc/stdlib/malloc.c:201: could not locate special linker symb
ol __gp
/usr/local/v810/lib/libc.a(sbrkr.o): In function `sbrk_r':
/home/Dan/vb_v810_gcc_03/newlib_build/v810/newlib/libc/reent/../../../../../newl
ib-1.10.0/newlib/libc/reent/sbrkr.c:60: undefined reference to `sbrk'
/home/Dan/vb_v810_gcc_03/newlib_build/v810/newlib/libc/reent/../../../../../newl
ib-1.10.0/newlib/libc/reent/sbrkr.c:60: relocation truncated to fit: R_V810_26_P
CREL sbrk
/usr/local/v810/lib/libc.a(reent.o): In function `reclaim_reent':
/home/Dan/vb_v810_gcc_03/newlib_build/v810/newlib/libc/reent/../../../../../newl
ib-1.10.0/newlib/libc/reent/reent.c:48: could not locate special linker symbol _
_gp
/usr/local/v810/lib/libc.a(reent.o): In function `wrapup_reent':
/home/Dan/vb_v810_gcc_03/newlib_build/v810/newlib/libc/reent/../../../../../newl
ib-1.10.0/newlib/libc/reent/reent.c:114: could not locate special linker symbol
__gp
collect2: ld returned 1 exit status
make: *** [all] Error 1
5 Replies

Hey Dan… nice to see you around again. I’ve never tried to use malloc on the VB, because I don’t think it’s supposed to work. Probably with a little work you could do it, but with the small amount of memory, I’m not sure you’d want to. I assume it doesn’t work because we have no heap space. But if you start allocating and deallocating memory on the heap, it can get fragmented quickly and waste a lot of space.

I’m no expert on this subject, but David Tucker could probably give you a lot of insight into it, and maybe give you ideas how to fix it if you wanted to.

What’s the need for dynamic allocation though? Can’t you just declare arrays/variables statically and just reuse them (you could even just declare a big chunk and make pointers for the various uses, as long as you keep track of which ones you can use at which times)?

DogP

I just thought it would be practical for a linked list with the enemies and items in zelda, but I already have it working the way I need it to using static arrays instead, so no biggie… 🙂

Ah… yep… when I was working on Mario, I created a linked list kinda thing w/ static arrays as well.

DogP

DanB: so u are working on Zelda vb game? or maybe ur starteing on Virtual Wario Ware again?

Hi guys, DanB I have a generic solution for this kind of stuff in my engine, you just need to grab the following classes:

MemoryPool: which does exactly the same as DogP says, that is to allocate static arrays of memory, but it’s generic so you can just ask it to allocate/deallocate space for your data no matter what kind of.

VirtualList: it’s a generic list like that in stl (with some limitations) and uses void* pointers to hold any kind of data.

I wrote to David T. a while ago asking about malloc/free and he told me that to activate it in the compiler it would be mandatory to reserve 32KB from the 64KB of work RAM for the heap, so it’s completely impractical.

BTW, I have newer versions of those classes which I have not released yet, if any one is interested in them just PM me :-).

jorgeche

 

Write a reply

You must be logged in to reply to this topic.