Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,767 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Strange malloc behaviour/ seltsames malloc Verhalten #255511
03/10/09 23:46
03/10/09 23:46
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline OP
Member
KDuke  Offline OP
Member
K

Joined: Mar 2009
Posts: 112
Germany
[English]
Hi people,

sorry for annoying you again though this engine appears to get stranger every day I use it.
If I use malloc to allocate an amount of memory I can access elements outside the allocated space.
Normally I would expect an exception though the overflow doesn't seem to affect performance at all confused
Does the engine manage such situations or is it unable to recognize overflows of such simple kinds?
Simply take a quick glance at the sample code please.

[German]
Hi Leute,

entschuldigung dafür, dass ich euch schon wieder nerve, jedoch scheint diese Engine jeden Tag, den ich sie benutze, seltsamer zu werden.
Wenn ich malloc nutze, um Speicher zu allozieren, kann ich auf Elemente außerhalb des allozierten Raums zugreifen.
Normalerweise würde ich eine Ausnahme erwarten, jedoch scheint der Overflow die Performance in keinster Weise zu beeinflussen confused
Verwaltet die Engine solche Situationen, oder ist sie einfach nicht in der Lage solche einfachen Overflows zu erkennen?
Schaut auch einfach mal kurz den Beispielcode an.

Code:
function myFunction()
{
   byte* myText = (byte*)malloc(1);
   myText[4] = "e";
   // the following line outputs an `e' in a messagebox
   // die folgende Zeile gibt ein `e' in einer Messagebox aus
   printf("%c", myText[4]);
}



Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: Strange malloc behaviour/ seltsames malloc Verhalten [Re: KDuke] #255522
03/11/09 01:35
03/11/09 01:35
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
The engine allows you to access outside the malloc'ed area because it doesnt check youve stayed inside.
Real C, C++ and even C# dont check for this either. Thats up to you...

One point to remember though, when using "sizeof" in 3dgs, always precede it with (int) if you are multiplying it.
Code:
BMAP* BmapList = (BMAP*)malloc((int)sizeof(BMAP)*15);
Otherwise the size is not calculated correctly.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Strange malloc behaviour/ seltsames malloc Verhalten [Re: EvilSOB] #255535
03/11/09 06:34
03/11/09 06:34
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline OP
Member
KDuke  Offline OP
Member
K

Joined: Mar 2009
Posts: 112
Germany
Hi EvilSOB,

thanks for clarifying this. I guess I'm just totally spoiled because of Java.
The Java Virtual Machine throws you to death with exceptions if you go outside the allowed subscription range.
By the way, I already implemented the type casting everywhere I use "sizeof" because of your answers from my last thread.

Can't say it often enough... thank you again smile
You definitely are of big help... I hope I can be of help as well for you soon wink

greetings
KDuke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: Strange malloc behaviour/ seltsames malloc Verhalten [Re: KDuke] #255542
03/11/09 07:45
03/11/09 07:45
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
You're welcome. Give it time and Im sure you will.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1