Raised This Month: $ Target: $400
 0% 

why this code run


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LinLinLin
Senior Member
Join Date: Sep 2021
Old 04-25-2024 , 12:32   why this code run
Reply With Quote #1

PHP Code:
enum struct test
{
    
int  type;
    
char info[128];
    
char file[128];
    
char name[128];

    
ArrayList looking;
}

ArrayList mytest = new ArrayListsizeof(test) ); 
By reading and writing to this arraylist i am sure the code work well.
My question is why we can use sizeof to a enum struct which contain a arraylist? It's size is dynamic!

Last edited by LinLinLin; 04-25-2024 at 12:33.
LinLinLin is offline
little_froy
Senior Member
Join Date: May 2021
Old 04-25-2024 , 13:30   Re: why this code run
Reply With Quote #2

an ArrayList(or more than 1) each is a cell as the variable. for a cell, you can use sizeof, just like C pointer, itself is always 4 or 8 byte, but it's unrelated to how many memory it allocated.

Last edited by little_froy; 04-25-2024 at 17:50.
little_froy is offline
Earendil
Senior Member
Join Date: Jan 2020
Location: Spain
Old 05-13-2024 , 06:18   Re: why this code run
Reply With Quote #3

As far as I know, enum structs in SP works as an array, where each cell you define variables or methods. sizeof(test) gives you the size of the enum struct, in this case is 5.
__________________
>>My plugins<<
>>GitHub<<
Earendil is offline
LinLinLin
Senior Member
Join Date: Sep 2021
Old 05-14-2024 , 13:18   Re: why this code run
Reply With Quote #4

Quote:
Originally Posted by Earendil View Post
As far as I know, enum structs in SP works as an array, where each cell you define variables or methods. sizeof(test) gives you the size of the enum struct, in this case is 5.
but the size of enum strcut is dynamic because the arraylist in it.
Can arraylist use a dynamic num as block size?
LinLinLin is offline
LinLinLin
Senior Member
Join Date: Sep 2021
Old 05-14-2024 , 13:22   Re: why this code run
Reply With Quote #5

ok, i am stupid.
enum struct just store the handle of arraylist, not the data in it.
LinLinLin is offline
Earendil
Senior Member
Join Date: Jan 2020
Location: Spain
Old 05-20-2024 , 04:56   Re: why this code run
Reply With Quote #6

Quote:
Originally Posted by LinLinLin View Post
ok, i am stupid.
enum struct just store the handle of arraylist, not the data in it.
Exactly, question solved.
__________________
>>My plugins<<
>>GitHub<<
Earendil is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode