NDS and using virtual methods - it's a good idea?
NDS and using virtual methods - it's a good idea?
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.
Re: NDS and using virtual methods - it's a good idea?
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.
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.
-
- Site Admin
- Posts: 1988
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: NDS and using virtual methods - it's a good idea?
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.
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.
Re: NDS and using virtual methods - it's a good idea?
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.
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 ;).
But you're right. I have no reason not to try use it. Thanks.
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.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.
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 ;).
Re: NDS and using virtual methods - it's a good idea?
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.
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.
Re: NDS and using virtual methods - it's a good idea?
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).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.
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).
Who is online
Users browsing this forum: No registered users and 0 guests