469,320 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

memory allocated for arrays in perl

dear friends
thanks for the mail sent
today i have one more question:
1. since in perl arrays need not be declared, [i.e arrays are expandable], what is the maximum limit of elements an array could have?
2. in java/ c/ c++, if we declare an array with 5 elements it can have utmost 5 elements, and we could also know what is the memory allocated for an array. how do we know it in perl
3. how many bytes does a scalar , array, list and hashes occupy.
though most of the questions are elementary, but iam unable to get answers for these from the other books and hence i request the board members to clarify it
with regards
rathankar
Oct 7 '07 #1
2 3996
numberwhun
3,503 Expert Mod 2GB
dear friends
thanks for the mail sent
today i have one more question:
1. since in perl arrays need not be declared, [i.e arrays are expandable], what is the maximum limit of elements an array could have?
2. in java/ c/ c++, if we declare an array with 5 elements it can have utmost 5 elements, and we could also know what is the memory allocated for an array. how do we know it in perl
3. how many bytes does a scalar , array, list and hashes occupy.
though most of the questions are elementary, but iam unable to get answers for these from the other books and hence i request the board members to clarify it
with regards
rathankar
Well, the answer to your first question is, it depends on the amount of memory in your system and what you are storing in your arrays.

To find out ( through your own research) how much memory is used by perl variables (arrays, hashes, etc), I did a search on CPAN and discovered the module Devel::Size which does something similar to what you are asking.

Regards,

Jeff
Oct 7 '07 #2
KevinADC
4,059 Expert 2GB
Perl does not put any limits on how much memory variables can store. They will use all available memory if necessary. In general you almost never worry about memory issues with perl unless you are processing large amounts of data. By defining your variables lexically perl frees up memory as variables go out of scope. The allocaion of memory to arrays is not very efficient though if my own memory serves me. In the name of faster processing perl allocates large chunks of memory to arrays instead of adding memory as necessary when an array grows larger.

You might want to ask ths question on www.perlmonks.com where there are more members with mor experience with these type of developer questions.
Oct 7 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

53 posts views Thread by fdmfdmfdm | last post: by
11 posts views Thread by mast2as | last post: by
27 posts views Thread by George2 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.