|
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn),
581
guests, and 0
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: How do I malloc an array of panels?
[Re: Caermundh]
#295099
10/22/09 23:07
10/22/09 23:07
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
PANEL* my_panels[50];
void init_panels_startup(){
var i = 0;
for(i=0;i<50;i++)my_panels[i] = malloc(sizeof(PANEL));
}
that's all just paste it to your code somewhere, function will run automatically at startup without calling it. (functions ending with _startup does that.)
3333333333
|
|
|
Re: How do I malloc an array of panels?
[Re: Caermundh]
#295103
10/22/09 23:23
10/22/09 23:23
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
hmm strange, are you sure you are writing PANEL* my_panels[50]; and not PANEL my_panels[50]; or PANEL my_panel; ?? this code alone compiles and runs fine for me:
PANEL* my_panels[50];
void init_panels_startup(){
var i = 0;
for(i=0;i<50;i++)my_panels[i] = malloc(sizeof(PANEL));
}
3333333333
|
|
|
Re: How do I malloc an array of panels?
[Re: Caermundh]
#295105
10/22/09 23:48
10/22/09 23:48
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
PANEL* my_panels[50]; because if i did there would be no need to malloc.
wrong. you only get space for PANEL pointers this way, not the actual panels, you still need to alloc space for them.
3333333333
|
|
|
Re: How do I malloc an array of panels?
[Re: Caermundh]
#295106
10/22/09 23:49
10/22/09 23:49
|
Joined: Aug 2008
Posts: 133 Sweden, Stockholm
Enduriel
Member
|
Member
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
|
PANEL* my_panels[50]; is an array of pointers, basicly 32 bit memory adresses with no content. EDIT: lolz quadraxas 49 seconds before me 
Last edited by Enduriel; 10/22/09 23:49.
|
|
|
Re: How do I malloc an array of panels?
[Re: Caermundh]
#295110
10/22/09 23:59
10/22/09 23:59
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
in that case, you need a PANEL** which wil point to your PANEL*s like
PANEL** my_panels;
void panels_startup(){
my_panels = malloc(sizeof(PANEL*)*120);
//at this point you basically have space for 120 panel pointers, 120 can be a variable
var count = 0;
for(count=0;count<120;count++) my_panels[count] = malloc(sizeof(PANEL));
//making my panel pointers to point to something.
}
ps you could also use for(count=0;count<120;count++) my_panels[count] = pan_create("panel definition goes here"); instead of mallocs. check pan_create from manual for that. AND if you need your panel number to decrease/increase after creating the initial array, use linked-lists.
3333333333
|
|
|
|