Jump to content

Any overhead for Empty array elements?


 Share

Recommended Posts

Hi All,

Not sure about correct wording but hopefully you'll understand.

I am looking at doing a script/app that I'm not sure how large it could grow and am curious as to whether or not array elements(cells) take up any space (resources/overhead?) if many are not used.

Here's an example using a 2d array:

$array[20][6]

[name1][c1][c2][c3][c4][c5][c6]

[name2][c1][c2][c3][c4][c5][c6]

[name3][c1][c2][c3][c4][c5][c6]

[name4][c1][c2][c3]

[name5][c1][c2][c3]

[name6][c1][c2][c3]

[name7][c1][c2][c3]

as you can see i have to make it 6 wide for some entires need it but is there any waste for those that don't, say if you get into 10's of thousands of entries.

thx Much

A.B.Ames

Link to comment
Share on other sites

afaik this is not possible in autoit.

my best suggestion would be to use a text file.

I Guess I explained it wrong (i always do). I am bringing this data in from a text file and populating the array with it. Each line of text is a row (r for row in array[r][c]) and each lines data is split up to make the columns (c for columns in array[r][c]) but as some of the lines only have data to populate 3 or 4 columns and some 6 or 7 then i end up with many empty elements(cells?)

$array[20][6]

[name1][c1][c2][c3][c4][c5][c6]

[name2][c1][c2][c3][c4][c5][c6]

[name3][c1][c2][c3][c4][c5][c6]

[name4][c1][c2][c3][E ] [E ] [E ]

[name5][c1][c2][c3][E ] [E ] [E ]

[name6][c1][c2][c3][E ] [E ] [E ]

[name7][c1][c2][c3][E ] [E ] [E ]

E = empty, no data from text lines to populate them.

Hope this is better example

Thx Much

A.B.Ames

Link to comment
Share on other sites

The answer is yes, empty elements take up memory.

I ran the following script:

MsgBox(0, "Test", "Basic script memory size")
Dim $a[16000][1000]; Maximum array size

MsgBox(0, "Test", "Memory with large array dimensioned")
$a = 0

MsgBox(0, "Test", "Large array cleared")

At the first MsgBox, Task Manager showed that AutoIt was taking 3.2MB of memory. At the second MsgBox, the memory had jumped to 65.8MB. At the third MsgBox, memory had returned to 3.3MB.

Edited by bluebearr
BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

im sorry i misinterpetet your question.

is this the awnser you want:

EDIT: Sorry Posted this before seeing bluebearr's reply.

Thx wOuter but i still must have miss-worded the question, I was aware of the Limits of the number of elements (and dimensions) but I was curious to if empty elements take up a certain amount memory space (resourses, or anything?) when the script is running.

As a none related example is to say that a pail (the array element) can hold a gallon of water (the data) but even when a pail is empty I still can only fit so many pails in my cupboard as they take up space themselves. So do even empty array elements take up a certain amount (of anything)?

Hope this helps better,

Thx Again for replying

A.B.Ames

Edited by A.B.Ames
Link to comment
Share on other sites

The answer is yes, empty elements take up memory.

I ran the following script:

MsgBox(0, "Test", "Basic script memory size")
Dim $a[16000][1000]; Maximum array size

MsgBox(0, "Test", "Memory with large array dimensioned")
$a = 0

MsgBox(0, "Test", "Large array cleared")

At the first MsgBox, Task Manager showed that AutoIt was taking 3.2MB of memory. At the second MsgBox, the memory had jumped to 65.8MB. At the third MsgBox, memory had returned to 3.3MB.

Thx bluebearr,

Thats what i was lookingt for (I should have thought of doing something like that myself).

I'll have to play around somemore and find a way to keep the number of empty elements to a min for what i need then.

Again, Thx

A.B.Ames

Link to comment
Share on other sites

  • Developers

See here for an explanation how Arrays are initialized... ;)

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

See here for an explanation how Arrays are initialized... ;)

Thx JdeB,

Very helpful, most of it is well above me though but i got the basic understanding, and it also helped me understand another problem (though i had already found a workaround) i encountered about searching for and using the next empty elements.

Many Thx

A.B.Ames

Link to comment
Share on other sites

If I were in your situation I would use a single-dimensioned array where the element would indicate the appropriate row, and then I would store the data as some sort of delimited string within:

Data for col. 1|Data for col. 2|||Data for col. 5|

where data for columns 3, 4 and 6 doesn't exist. This will result in (almost) no memory being occupied for columns with no data.
Link to comment
Share on other sites

If I were in your situation I would use a single-dimensioned array where the element would indicate the appropriate row, and then I would store the data as some sort of delimited string within:

Data for col. 1|Data for col. 2|||Data for col. 5|

where data for columns 3, 4 and 6 doesn't exist. This will result in (almost) no memory being occupied for columns with no data.
Hi LxP,

Thx for your input, I won't have to worry about the extra columns now as i have looked over it and the extra data (from those columns) is not needed all the time so I will be setting it up to only look up that extra data from the txt file only as needed. BTW I am actually working with a 3 dimension array, I just used the 2dim as a example to keep it simple (but this may change to depending on what i decide below).

What i had intended (it may sound wierd but i have only done a few scripts so far so i' just learning how all this works) was to use the 1st dimension for a Category ID# list (say like folders), the 2nd dimension for name, description, details, etc., and the 3rd dimension for the items that are located within each category's ID using the 1st array's number (Array[1]) as the ID#. This way I was hoping to make it easier to obtain all items with in a certain category without searching though nearly all the array. In otherwords when I select Category 2 and want to see all in that category I can just call array[2][x][x] (x = cycle from 0 to last element), then i'd have all in category 2 without searching through array[1][x][x], [2][x][x]-->[100][x][x]. I really don't know if this is correct but i'm trying.

But now on the otherhand what you shown me here really makes me re-think and wonder what way would be better, as the lines of data i am putting into the array already have delimiters separating the sections.

So would it be better for access and speed to split the data (via delimiters) and then put it into the arrays or to put it in (using less dimensions and a larger string) and then split it as it is accessed.

So simplified:

File->Split->Array[][][]->User

or

File->Array[][]->Split->User

A 1 dimension array would (I believe) unfortunately require a search through all records each time user accessed a category so i don't think it would work, not sure though?

Any comments on which may work better?

Thx Much

A.B.Ames

Link to comment
Share on other sites

One of my favorites

#include <Array.au3>

$days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",")
;$days[1] contains "Sun" ... $days[7] contains "Sat"

_ArrayDisplay($days, " My Array")

8)

Hi Valuater,

Yes i agree and am currently using this (or nearly it anyway) as a temp array for each line before sending it's data to populate elements in 3 dimension array.

So does this mean you prefer splitting up all the data before array (for faster access?).

another (2d) sample using week & days:

splitstring to array and user calls only one element as needed

$array[4][8]

[week1][day1][day2][day3][day4][day5][day6][day7]

[week2][day1][day2][day3][day4][day5][day6][day7]

[week3][day1][day2][day3][day4][day5][day6][day7]

[week4][day1][day2][day3][day4][day5][day6][day7]

vs

$array[4]

[week1;day1;day2;day3;day4;day5;day6;day7]

[week2;day1;day2;day3;day4;day5;day6;day7]

[week3;day1;day2;day3;day4;day5;day6;day7]

[week4;day1;day2;day3;day4;day5;day6;day7]

user calls an element then splitstring (; delimiter) for data section needed by user

Thx much

A.B.Ames

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...