By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,172 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,172 IT Pros & Developers. It's quick & easy.

memory allocated for arrays in perl

P: 4
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
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Expert 2.5K+
P: 4,059
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.