Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (ozgur, TipmyPip, AndrewAMD), 1,209 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Autosizing string [Re: Uhrwerk] #413383
12/12/12 23:34
12/12/12 23:34
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline
Junior Member
Talemon  Offline
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
Originally Posted By: Uhrwerk
Originally Posted By: Ercoles
So how should they be defined locally?

Not at all. A STRING* is an engine object. Allocation is costly. You should use global or static strings whereever possible. If you have good reason to create a local string with str_create don't forget to free them afterwards, or you'll create a memory leak.

Well when you define them globally, they will still be allocated. Also, if you don't free them it won't technically be a memory leak since the engine frees them on exit. It would be memory bloat though in the course of the game's runtime.

Re: Autosizing string [Re: Talemon] #413386
12/13/12 02:19
12/13/12 02:19
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
When defining strings globally they are allocated exactly one time. When you create strings in functions with str_create they will be created as many times as the function is called.

I don't think it's of any interest if the engine frees them before exiting or if the memory gets freed when the process is being killed by the operating system. In fact it's memory that was allocated and still cannot be used. Also note that the number of engine objects is limited. So not freeing strings when creating them in a function is a rather bad idea, regardless if that counts technically as a memory leak or not.


Always learn from history, to be sure you make the same mistakes again...
Re: Autosizing string [Re: Uhrwerk] #413387
12/13/12 04:19
12/13/12 04:19
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
It technically is a memory leak since you lost all references to it. It doesn't matter if there are still references to it somewhere else, it becomes a memory leak as soon as you lose the last reference to it. Obviously you can have indirect references to an object (ie store it in an array and throw the pointer away but keep a reference to the array), but the engine doesn't count as indirect reference but as blackbox that you don't have a control over.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Autosizing string [Re: Uhrwerk] #413398
12/13/12 09:56
12/13/12 09:56
Joined: Apr 2011
Posts: 75
Malta
E
Ercoles Offline OP
Junior Member
Ercoles  Offline OP
Junior Member
E

Joined: Apr 2011
Posts: 75
Malta
I am a bit confused. When I declare a variable I use:

var x;

for integer I use int, for floating point I use float and for string I use:

STRING* word;

or is there another way?

Page 2 of 2 1 2

Gamestudio download | chip programmers | 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