Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (ozgur, howardR, AndrewAMD, exile, Ayumi), 725 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: ptr_remove and array -> memory poblem [Re: Reconnoiter] #443885
07/27/14 13:44
07/27/14 13:44
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
As a general rule, if you think "wouldn't it be great if XYZ would work and I could make my code cleaner", the answer is: "It does work!"

Here is some code snippet that probably does what you want:
Code:
PANEL *pointer_pan[4][31];

void initialize()
{
	memset(pointer_pan, 0, 4 * 31 * sizeof(PANEL *));
}

void cleanup()
{
	int i, j;

	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 31; j ++)
		{
			if(pointer_pan[i][j])
			{
				ptr_remove(pointer_pan[i][j]);
				pointer_pan[i][j] = NULL;
			}
		}
	}
}



You may want to learn/read up a bit on basic programming and/or read some code written by others with experience.
Note that the memset() trick doesn't work with dynamically allocated multidimensional arrays, because in reality this is still a flat, contiguous block of memory. The compiler will translate the 2D access into a single offset into the memory block.

Last edited by JustSid; 07/27/14 13:46.

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: ptr_remove and array -> memory poblem [Re: WretchedSid] #443983
07/28/14 15:20
07/28/14 15:20
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hi WretchedSid grin ,

Quote:
As a general rule, if you think "wouldn't it be great if XYZ would work and I could make my code cleaner", the answer is: "It does work!"
, not a bad rule, but you first have to think it / come with the idea tongue.

Quote:
memset(pointer_pan, 0, 4 * 31 * sizeof(PANEL *));
, what does memset do? Allocate memory? I can't find it as a function in the manual.

Concerning the code I am almost there, not much longer till the bug is squished. I get a crash when trying to show this text though (last line does it). It is probably something stupid but I am getting a bit dizzy of all those arrays (even when they look clearer now thanks to you and Superku).

Code:
TEXT* pointer_text_dir[4];

function init_arraysandpointers_startup()
{
 var i, j;
 //create array text dir
 for(i = 0; i < 4; i++)
 {
  pointer_text_dir[i] = txt_create(30,21);
  pointer_text_dir[i].pos_x = 10;
  pointer_text_dir[i].pos_y = 135;
  pointer_text_dir[i].layer = 21; 
  pointer_text_dir[i].font = "Calibri#20";
  vec_set(pointer_text_dir[i].blue,vector(155, 255, 155));
 }
...
} 
 
 ...
 ...

 //clean up earlier created txt strings
 var i, j;
 for(i = 0; i < 4; i++)
 {
  for(j = 0; j < 30; j++) str_cpy((pointer_text_dir[i].pstring)[j],"");
 }

...
...

filesfound_var = txt_for_dir(pointer_text_dir[0],"Folder 1\\*.mdl");
set (pointer_text_dir[0],SHOW);



Quote:
You may want to learn/read up a bit on basic programming and/or read some code written by others with experience.
, fair enough, I do already try alot through manual and sometimes AUM. And those weekly tips from e.g. Superku. I will look around some more though.

Re: ptr_remove and array -> memory poblem [Re: Reconnoiter] #444037
07/29/14 14:12
07/29/14 14:12
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
I'm afraid I can't help you with txt_for_dir(). Someone else want to pitch in?

Anyways, I can help you with memset(). It's a function from the C standard library and it sets the content of a given memory block to the given constant. In the example case it was set to 0, so the block of memory was zeroed out. It's short than the for loop, and potentially faster: Usually the library shipped with the system has an optimized version for your CPU, which takes advantage of the big guns in the instruction set (in the case of modern x86 CPUs this means it uses AVX to store 512bits at once)


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: ptr_remove and array -> memory poblem [Re: Reconnoiter] #444040
07/29/14 14:47
07/29/14 14:47
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
This line can cause crash pointer_text_dir[i].font = "Calibri#20";
You should use font_create. pointer_text_dir[i].font =font_create("Calibri#20");

Re: ptr_remove and array -> memory poblem [Re: Emre] #444041
07/29/14 15:00
07/29/14 15:00
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Quote:
This line can cause crash pointer_text_dir[i].font = "Calibri#20";
This line must cause a crash because "Calibri#20" is not a font but just some characters.

You'r 2nd example should work, although it's better to define the font globally.


POTATO-MAN saves the day! - Random
Re: ptr_remove and array -> memory poblem [Re: Kartoffel] #444042
07/29/14 15:27
07/29/14 15:27
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
yesyesyes I works perfect now, luv you all grin

Re: ptr_remove and array -> memory poblem [Re: Reconnoiter] #444043
07/29/14 15:37
07/29/14 15:37
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Originally Posted By: Reconnoiter
yesyesyes I works perfect now, luv you all grin

it's good to know! And Kartoffel is right. It is better to declare globally, than create the same font again for each text. wink

Re: ptr_remove and array -> memory poblem [Re: Emre] #444044
07/29/14 15:43
07/29/14 15:43
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Yes I did like this globally now:

FONT* calibri20_font = "Calibri#20";
...
...
pointer_text_dir[i].font = calibri20_font;

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