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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, degenerate_762), 1,309 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Set struct array free #436841
02/03/14 18:41
02/03/14 18:41
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Hi I just need to now how to set the memory area free.
I know I can use the free() funktion to do that. But how I have to write for a pointer array?

Here is the code:

Code:
typedef struct GRAPH
{
	POINT **points; // Knoten-Array
	
} GRAPH;

void f_create_graph(var num_points)
{
	// create
	
	GRAPH* graph = malloc(sizeof(GRAPH));
	
	graph.points = (POINT **)malloc(num_points * num_points * sizeof(POINT*));

	// set free
	
	free(graph.points);
	
	free(graph);
}



I think free(graph.points); is incorrect to set the complete pointer array free, or is it right?

Re: Set struct array free [Re: Benni003] #436842
02/03/14 18:46
02/03/14 18:46
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
It is. You balance out malloc() calls with free() calls.

You are also not explicitly allocating an array, at least not as far as the OS, CPU, TLB or RAM is concerned. All you do is request a contiguous block of memory.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Set struct array free [Re: WretchedSid] #436843
02/03/14 18:49
02/03/14 18:49
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Thank you, also for your fast answer laugh


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

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