Hi Lux,
I might do that.
I suppose a transparent overlay like that could be used to put clouds in different parts of a game like nebuli in a space game.
Asimov
Malloc and New
Re: Malloc and New
- Attachments
-
- PerfRes.jpg
- (286.2 KiB) Downloaded 80 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Malloc and New
Hi Chilli,
I was researching using new instead of Malloc LOL, and failed big time.
Thought I could initialize my class with
LoadSpr png = new LoadSpr();
and it didn't quite work.
Well failure is part of learning heh heh.
Asimov
I was researching using new instead of Malloc LOL, and failed big time.
Thought I could initialize my class with
LoadSpr png = new LoadSpr();
and it didn't quite work.
Well failure is part of learning heh heh.
Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Malloc and New
Just like malloc, you need to use a POINTER Asimov.
i.e. LoadSpr* png = new LoadSpr;
i.e. LoadSpr* png = new LoadSpr;
Chili
Re: Malloc and New
Hi Chilli,
I tried that and I get a red squiggle under the equals sign.
Think I will wait until the new tutorials LOL. I probably have to add something to the class too to make it work anyway.
Got a ton more models to build and my brother is coming to visit today anyway heh heh.
Asimov
I tried that and I get a red squiggle under the equals sign.
Think I will wait until the new tutorials LOL. I probably have to add something to the class too to make it work anyway.
Got a ton more models to build and my brother is coming to visit today anyway heh heh.
Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Malloc and New
Look at your results above, your computer should be running just fine.
I haven't been doing much coding right now, but I'll see if I get my game done in the couple next days, so you can have a look how I did it in my game and maybe get it working for you.
I made some research on malloc, it seems malloc shouldn't be any slower, however there is a case where it might slow down. Malloc tries to find a memory block equal or larger to its size, but if such can't be found, it will look for multiple smaller blocks and use those. In that case malloc will slow down, the more it has to jump around in memory.
http://mikehearn.wordpress.com/2006/10/ ... tion-slow/
Not sure how relevant that is in the current version of c++
I haven't been doing much coding right now, but I'll see if I get my game done in the couple next days, so you can have a look how I did it in my game and maybe get it working for you.
I made some research on malloc, it seems malloc shouldn't be any slower, however there is a case where it might slow down. Malloc tries to find a memory block equal or larger to its size, but if such can't be found, it will look for multiple smaller blocks and use those. In that case malloc will slow down, the more it has to jump around in memory.
http://mikehearn.wordpress.com/2006/10/ ... tion-slow/
Not sure how relevant that is in the current version of c++
ʕ •ᴥ•ʔ
Re: Malloc and New
Hi Chilli,
Hey just replaced malloc with new in my sprite loader and it worked woohoo
Now in my game deconstructor where I call freesprite for malloc would I change it from this
to this
Asimov
Hey just replaced malloc with new in my sprite loader and it worked woohoo
Code: Select all
void SpriteLoader::LoadSprite(const wchar_t* filename, int sWidth,int sHeight,int nFrames,int tWidth )
{
//surface = (D3DCOLOR*)malloc( sizeof( D3DCOLOR ) * tWidth * sHeight );
surface = new D3DCOLOR[ tWidth * sHeight ]; //Changed here
LoadPNG(filename);
SpriteHeight=sHeight;
SpriteWidth=sWidth;
Frame=0;
Time=0;
NumberOfFrames=nFrames;
}
Now in my game deconstructor where I call freesprite for malloc would I change it from this
Code: Select all
void SpriteLoader::FreeSprite()
{
free (surface);
}
Code: Select all
void SpriteLoader::FreeSprite()
{
delete [] surface;
}
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk