NDS and using virtual methods - it's a good idea?

support for the ARM toolchain
Post Reply
Laethnes
Posts: 5
Joined: Sun Sep 27, 2009 8:31 am

NDS and using virtual methods - it's a good idea?

Post by Laethnes » Mon Sep 28, 2009 6:42 pm

I'm just beginning programme to NDS (but in C++ I'm programming a few years) and I'm thinking about virtual methods. I made a simple video engine for PC game using virtual functions, co I can later change graphic library from OpenGL to Direct3D or so and so I did with classes for images, textures, models and so. Thanks to all of these, it is possible use my engine (collisions, scene managers, ...) in NDS with little work. But almost everything uses virtual methods. And my problem is - isn't it too expensive for system like NDS? I have only 4MB of memory, not a few GB, like on PC. So, should I use this my engine, or should I alter/remake it to NDS with little virtual methods as possible? Or is this thing insignificant? Because on NDS you cannot choose video system - it makes no sense. So there is only one possible class to manage it, and so there is only image/texture class. But if I should remake it, it would me less portable code.

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

Re: NDS and using virtual methods - it's a good idea?

Post by vuurrobin » Mon Sep 28, 2009 10:24 pm

there is nothing wrong with virtual methods as long as you don't overdo it. so it really depends on your engine.

if its really easy to port, then I suggest that you try it out. if it works, great! if not, then you need to change your engine.

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: NDS and using virtual methods - it's a good idea?

Post by WinterMute » Tue Sep 29, 2009 12:59 am

To be honest, you're probably the best person to make that judgement - you've already said that it would take little work to port your engine so just go for it. Once you have the initial port done you'll have a better idea of the memory requirements.

Classes and virtual methods don't generally use a lot of memory - the things you have to watch out for are memory fragmentation and some parts of STL. std::cout is a particular memory hog.

To combat memory fragmentation you need to pay attention to the order of allocation. Large, long lived allocations should precede smaller, short lived ones. For game use it can often be better to allocate a large pool for game objects and manage that block in your own code rather than use malloc/free during the game.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Laethnes
Posts: 5
Joined: Sun Sep 27, 2009 8:31 am

Re: NDS and using virtual methods - it's a good idea?

Post by Laethnes » Tue Sep 29, 2009 7:35 am

But I'm not sure, what means "overdo it" for system like NDS. Because I'm using and operating through interface classes, every method I need have to be virtual. It's not like I'm using hundreds of methods, but it doesn't sound nice to me.

But you're right. I have no reason not to try use it. Thanks.
WinterMute wrote:Classes and virtual methods don't generally use a lot of memory - the things you have to watch out for are memory fragmentation and some parts of STL. std::cout is a particular memory hog.
Yea, it was yesterday (or day before) I read (in general, not nds) about memory fragmentation. Since then I'm thinking about howto change system with short-live objects :3.

About std::cout I did not know. It is std::cout only, or other streams (stringstream, which I'm using offten) too?

Thanks for tips and support, both of you ;).

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

Re: NDS and using virtual methods - it's a good idea?

Post by vuurrobin » Tue Sep 29, 2009 8:00 am

if you don't have that many virtual functions, then just try it.


about std, I suggest you read this:
http://www.coranac.com/2009/02/some-int ... code-size/

although stringstream isn't included, so I'm not sure how big it is.

Laethnes
Posts: 5
Joined: Sun Sep 27, 2009 8:31 am

Re: NDS and using virtual methods - it's a good idea?

Post by Laethnes » Tue Sep 29, 2009 10:13 am

vuurrobin wrote:about std, I suggest you read this:
http://www.coranac.com/2009/02/some-int ... code-size/

although stringstream isn't included, so I'm not sure how big it is.
OMG! And I thought that basic iostream is lighter then printf... Yea, stringstream is not there, but it is obvious, that it will take also large memory, because it needs iostream (because stringstreams ARE istream and ostream). Hm... 1/4 MB RAM is much... if I do not want to use it on NDS, it looks like problem with iostream is now my main problem, 'cause because of LOG and exception functions my code is full of iostream functions (I'm using them to make a final error message and so).
On the other hand, iostream are very comfort so... maybe I should write my own streams using *printf as light as possible :3 (and without using templates. I know they are powerful, but I do not use them).

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests