Jump to content
  • Advertisement
Sign in to follow this  

memory allocation - DS

This topic is 4031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Guys/Ladies ! i would like to allocate memory (heap) dynamically at Ninetendo DS, but I cannot do it... For example i would like to do something, like : int a; int *pa; a=5; pa=&a; but I fails... Later I would like this technics to extent to objects. Neither malloc, nor new.... nothing works (((( can anyone help me ? Cheers, Paolo

Share this post


Link to post
Share on other sites
Advertisement
sorry, perhaps I did not write my problem well. I emphasize, "dynamically". So something like with "new" command memory allocation. malloc is also welcomed...

Share this post


Link to post
Share on other sites
What exactly doesn't work about your example? You're not allocating memory dynamically but that should still work (unless of course this is in a function body and you return that pointer).

Share this post


Link to post
Share on other sites
Quote:
Original post by Monder
What exactly doesn't work about your example? You're not allocating memory dynamically but that should still work (unless of course this is in a function body and you return that pointer).


Exactly I am included in a group, whose intention is to write a game, like pacman. So there are monsters against the pac-man like figure. And I have created some basic class, to contain some behaviour of these monsters. There are a maximum of 8 number of monsters, but they do not appear all immediately at the beginning of the game, but after certain times. So at first there is no monster on the screen, then 1 monster appear, then two, etc. And sometimes not all the monsters appear, 8 is only a theoretically maximum number. Therefore I need dynamic memory allocation. This monster class - I was wondering - could look, like this :

class CMonster
{
private :
int monsterindex; // 1..8 - monster number in the rank
long posx,posy; // screen position of the center of the monster
int lastdir;


public :
BOOL active; // if false, not on the screen. true - on the screen
void EatEnvironment();
enum kind
{
NOBBIN,//basic monster, it can kill you, but cant eat wall
HOBBIN //it can eat everything(wall in the labirint as well)
};
int GetPosX();
int GetPosY();
CMonster();
void Vibrating(int posx,int posy);
void Draw();
void Generate(); // generate nobbin
void Move();
void Kill(); // player kills a monster
void Die(); // monster kill a player
BOOL GetActive();
BOOL Detect(long posx, long posy,long objx,long objy);
int timetoappear;

};

So I would like to create these monsters dynamically....
Is it a good idea ?

Paolo



Share this post


Link to post
Share on other sites
You need to use the SDKs own functions to allocate memory on the HEAP. See the Nitro SDK function reference for more information (subsection memory). You can then write your own custom allocator to use the new and delete operators.

You can also go to www.warioworld.com and register for the newsgroup. Post there to retrieve more information, because things are covered by an NDA, so you won't get any more information from here...

Share this post


Link to post
Share on other sites
Quote:
Original post by ZMaster
You need to use the SDKs own functions to allocate memory on the HEAP. See the Nitro SDK function reference for more information (subsection memory). You can then write your own custom allocator to use the new and delete operators.

You can also go to www.warioworld.com and register for the newsgroup. Post there to retrieve more information, because things are covered by an NDA, so you won't get any more information from here...


I have registered to the mentioned website. I have seen some example programm, but I cannot imagine, that I need big .h files, in order to apply dynamic memory allocation. It should be very simple, as it is often required in programming.

Share this post


Link to post
Share on other sites
Quote:
Original post by PaoloStoppa
I have registered to the mentioned website. I have seen some example programm, but I cannot imagine, that I need big .h files, in order to apply dynamic memory allocation. It should be very simple, as it is often required in programming.
You'll need "big .h files" to do dynamic allocation on PCs too. Except the code is in libraries.
For the DS, you just need to use the OS memory allocation call to allocate from the heap (It should be obvious what the function is, but I'm not able to post the name of it here for obvious reasons). That's sort of your malloc() function.

Share this post


Link to post
Share on other sites
In c, you need <malloc.h> to get memory allocation. It's the same on the GBA.

A dynamic memory allocator is a fairly complicated thing. It has to keep track of which parts of memory are used and which aren't. It's not a free operation, either, although it should be pretty fast.

You need to include the right header files and use the right (probably non-standard) functions to allocate memory on the DS.

If you don't believe us, that's your choice, but don't expect us to help if you can't/won't take our advice.

Share this post


Link to post
Share on other sites
Quote:
Original post by PaoloStoppa
It should be very simple, as it is often required in programming.


Nothing is simple when programming for consoles. non-PC hardware is _very_ fussy about how and when things are done.

Quote:
Original post by nagromo
It's not a free operation, either, although it should be pretty fast.


Memory allocation is often one of the slowest operations you can do. Certainly it appears "fast" for things with long lifetimes, but allocating memory will often be a bottleneck for things like particle engines or projectiles. That's why game programmers spend so much time writing memory managers that do only a single malloc at the beginning of the application and then just pass pointers to people asking for memory.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by nagromo
In c, you need <malloc.h> to get memory allocation. It's the same on the GBA.

A dynamic memory allocator is a fairly complicated thing. It has to keep track of which parts of memory are used and which aren't. It's not a free operation, either, although it should be pretty fast.

You need to include the right header files and use the right (probably non-standard) functions to allocate memory on the DS.

If you don't believe us, that's your choice, but don't expect us to help if you can't/won't take our advice.



Okey, I believe in people here. I read something like this in a code :

CMonster* pmonster. //see above, what is monster
OS_Init();

u32 arenaLow = ROUND_UP (OS_GetMainArenaLo(), 16);
u32 arenaHigh = ROUND_DOWN(OS_GetMainArenaHi(), 16);
u32 heapSize = arenaHigh - arenaLow;
void* heapMemory = OS_AllocFromMainArenaLo(heapSize, 16);
//int* pa;

gHeapHandle = NNS_FndCreateExpHeap(heapMemory, heapSize);
SDK_ASSERT( gHeapHandle != NNS_FND_HEAP_INVALID_HANDLE );

this works. Just after it I wanted to write

pFruitManager= new (CFruitManager);

but I received error message :

Panic:OS_AllocFromHeap(): heap not initialized. i received this message, when the breakpointer reached this line during debugging.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!