Re: wxEuphoria on FreeBSD
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Mar 31, 2007
- 665 views
Robert Craig wrote: > > The dirty assumptions that I make about malloc() have always > been a problem when porting. Yeah, I've been working on linux for a bit now, and I've discovered that (at least for FC6--not sure what version of libc that has) if you realloc smaller, and it gives you the same pointer back, malloc_usable_size() gives you the old answer, causing you to make invalid writes to memory. > > After banging my head for a while, I've come to the conclusion that the > > simplest way to get this to work is to just always malloc 8 more bytes > > than asked for, and put MAGIC_FILLER in for a 4 byte alligned chunk, > > and a 0 in for an 8 byte alignment. Of course, I'll have to memcopy > > in realloc if we switch alignments. > > Good idea. Just get it working cleanly. We can worry about > saving memory later. I haven't even really attempted to figure out what you do with all the cache and pool junk in there. > Subtle malloc bugs can be nightmarishly difficult to track down. > I'm impressed that you've figured out this much. > I hope you don't blame me for your torture. No, not really. Of course, a big issue is the rate of change in free and open source operating systems. I generally enjoy digging and digging until I figure out this sort of thing. I must say, valgrind really helps, especially when you remember to turn on debugging symbols (slaps head). Matt