Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
Lapsa's very own thread
by rki. 06/19/24 11:27
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 527 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
squik, AemStones, LucasJoshua, Baklazhan, Hanky27
19060 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: [SOLVED] Allocated memory + memset [Re: EvilSOB] #244297
01/03/09 22:37
01/03/09 22:37
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
Quote:
This one works for me. Tested with the array defined as
var* array = (var*)malloc((int)sizeof(var)*50);
memset(array[25], 0, 24 * 4);

I have tested this before with an int array. But for some reason it does not work with int arrays ("crash in main", although i am pretty sure it did not crash in the first place, but resulted in an uninitialized array).
However, with var (and other data types such as float and short) there aren't any problems indeed.
Well, I don't really know why. : )

Thank you for pointing this out.

Re: [SOLVED] Allocated memory + memset [Re: Saturnus] #244313
01/04/09 00:05
01/04/09 00:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Hmm, yes. Rather odd. I wonder why int's are handled differently?
Anyway, I testad a bit and came up with this that appears to work OK.
The one memset line is the important line you are after, and the rest is there
so you can see it in action, based on your original post in this thread.

As usual, any question or problems, just ask...
Code:
   // allocate memory for 100 integers
   int* array = (int*)malloc( (int)sizeof(int) * 100 );
   
   // initialize memory to 5's
   int i; for(i=0; i<100; i++) array[i]=5;
   
   // display int #11 on the screen (should be five)
   error(str_for_num(NULL, array[10] ));
   
   // display int #61 on the screen (should also be five)
   error(str_for_num(NULL, array[60] ));
   
   //reset elements 50-100 to zero
   memset(&(array[50]), 0, ((int)sizeof(int) * 50) );
   
   // display int #11 on the screen (should still be five)
   error(str_for_num(NULL, array[10] ));
   
   // display int #61 on the screen (should now be zero)
   error(str_for_num(NULL, array[60] ));
   
   //clean up when done
   free(array);



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [SOLVED] Allocated memory + memset [Re: EvilSOB] #244675
01/06/09 08:26
01/06/09 08:26
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
In this case I will stay with a for loop initialization, I think. However, I still have to check if a simple memset(array[25]...) works with my struct pointers.
I needed this for indexing the elements of a heap. When elements are added to the heap, the indexing array is reallocated if necessary. Then only a part of the array needs to be initialized. This is a rare case though, so a simple loop should do the job too. : )

Thanks for your effort.

// Edit
FYI: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=244692#Post244692

Last edited by Kombucha; 01/06/09 11:17. Reason: info added
Re: [SOLVED] Allocated memory + memset [Re: Saturnus] #244830
01/07/09 02:24
01/07/09 02:24
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
no problem, and thanks for the fyi


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

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