Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
I think I'm losing my memory...   Message List  
Reply | Forward Message #12048 of 15019 |
Re: [gbadev] Re: I think I'm losing my memory...

On 2 Jul 2002 at 19:39, colinraybrown wrote:

> --- In gbadev@y..., "Maciej Sinilo" <yrp@a...> wrote:
> ...
> > > and I get the same flaky behaviour and similar crashes.
> > Strange behaviour may be caused by memory overwrites, examine this
> > possibility.
> Yep this is a likely reason, but if my code is overwriting the wrong
> memory, how can it work flawlessly with the standard allocator?
> Theres a LOT happening for this kind of bug to go un-noticed, large
> parallax scrolling background - 40-60 actors, dynamic Sprite vram
> managment, dynamic background tile managment, multi-channel direct
> sound, score, lives, radar, collision testing etc etc... There are
> many objects being constructed and deleted as the game progresses...
> I find it hard to believe that there is a bug in the engine of this
> type that dosn't effect the standard new and delete...
> There probably is though :-|
> Now I have to chase that wild goose! (again)
That's where custom memory allocator may help. My GBA memory manager is not very
sophisticated, but it still should catch some problems like mem leaks (well, not
very important on GBA, I think) or overwrites.

> > ;-). The thing is that my new/delete operators prototypes differ a
> >little bit from "standard" one because new takes additional
> >arguments (zone). If you want I may send you
> > my version, you may test it and see if it still crashes.
>
> sounds very interesting, I thought 'new' was passed just a Size_t
> arguement automatically by the system as part of the construction
> process, and I had no control over this! What is the syntax for your
> extra arguement?
Very simple:
void* operator new(size_t size, int myExtraArg);
MyClass* m = new(1) MyClass; // myExtraArg = 1
This may come handy in things like zone-based mem allocator (like my one) or
when you like to pass file/line from where the new was called (I use this in my
PC engine).
The problem is that in C++ there's no such concept as placement delete. If you
use exceptions than you still need corresponding operator delete, ie:
void operator delete(void* ptr, int);
in order to have mem automatically deleted on exception thrown from constructor.
There's more to it, but it's not really GBA related.
If you examine my code you'll see there's no overloaded delete operator. That's
because I've no possibility to pass zone in elegant way. So I use custom Delete
template
which does the trick. Now when I think of it there should also be some
DeleteArray...

> It would be cool to have a look at your source.
Sure thing. If anyone else is interested:
http://www.msinilo.host.sk/download/EmpMemZone.h and
http://www.msinilo.host.sk/download/EmpMemZone.cpp. Please bear in
mind this is a part of bigger package so it won't compile as-is, but shouldn't
be very difficult to make it work without my routines (I think it only relies on
EMP_ASSERT).
Another thing I've to confess it wasn't really tested very heavily on GBA, but I
used almost the same code in my PC prods.

-- cheers,
Maciej

--
- Maciej Sinilo
- 7th Sense s.r.l.
- http://www.7th-sense.net







Wed Jul 3, 2002 8:00 am

yarpen2002
Offline Offline
Send Email Send Email

Forward
Message #12048 of 15019 |
Expand Messages Author Sort by Date

AAARRRGGGGHHHHH... Spent AGES trying to get my memory allocator to stop crashing, I've tried all sorts, and re-written much of it to no avail. So I tried a...
colinraybrown
Offline Send Email
Jul 2, 2002
12:25 am

... Strange behaviour may be caused by memory overwrites, examine this possibility. ... Hmm, I don't think this may be a reason, but you never know. I'm using...
Maciej Sinilo
yarpen2002
Offline Send Email
Jul 2, 2002
8:50 am

... Yep this is a likely reason, but if my code is overwriting the wrong memory, how can it work flawlessly with the standard allocator? Theres a LOT happening...
colinraybrown
Offline Send Email
Jul 3, 2002
2:11 am

... That's where custom memory allocator may help. My GBA memory manager is not very sophisticated, but it still should catch some problems like mem leaks...
Maciej Sinilo
yarpen2002
Offline Send Email
Jul 3, 2002
11:22 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help