Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Does DarkSDK use new or malloc for char* allocation??

Author
Message
Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 25th Feb 2006 19:28
Hi there,

just wondering whether DarkSDK uses "malloc" (C-style) or "new" (C++ style), when allocating memory such as for strings in DarkSDK string functions!?

It matters when you need to release the memory, what should you use, "free" (C) or "delete" (C++) ??

I guess its not good to mix them.. so this would be nice to know from someone who has insight into the code or if anyone knows anyways, pls tell me thanks!!

greets,
Barnski

-- I just started with DarkSDK, by translating DBP Projects. --
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Feb 2006 19:36 Edited at: 25th Feb 2006 19:36
Yes, you shouldn't mix free/delete with new/malloc/calloc

Nor should you mix delete arrays with delete vectors.

http://www.codeproject.com/tips/newandmalloc.asp

Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
Smoke me a computer chip, I'll be baking breakfast.
Kaiyodo
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: UK
Posted: 25th Feb 2006 23:06
According to my testing DarkSDK uses array new for its strings, i.e. var = new char[50];

'delete [] var;' would be the correct way to delete them.

I added breakpoints on operator new and malloc then called dbTextFont() and had a look which one got hit

Kaiyodo.
Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 26th Feb 2006 17:24
Ah thanx Kaiyodo, good idea btw

-- I just started with DarkSDK, by translating DBP Projects. --

Login to post a reply

Server time is: 2024-11-19 04:16:29
Your offset time is: 2024-11-19 04:16:29