473,410 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Optimization issue

Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a particular
point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in my grid.

I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each value
y*512+x added to the array tells me that in p(x,y) I have value True
Drawback: Search if there is a value like y*512 +x in my array can be
long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains, Remove for
adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how much
memory require

Anyway, I need the best compromise memory allocated - search for value - set
a value

Any advices?

I know I could test each one, just hope someone have allready done it :)

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
11 913
Why not

Dim BoolsGrid(511,511) As Boolean

'Access 255,255

If BoolGrid(255,255) Then

'I Found It to be True

End If
Regards - OHM

Crirus wrote:
Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a
particular point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in
my grid.

I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each
value y*512+x added to the array tells me that in p(x,y) I have value
True Drawback: Search if there is a value like y*512 +x in my
array can be
long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains,
Remove for adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how
much memory require

Anyway, I need the best compromise memory allocated - search for
value - set a value

Any advices?

I know I could test each one, just hope someone have allready done it
:)


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #2
BoolGrid(511,511) require the same memoy as myBitArray.Length(511*511)??

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
Why not

Dim BoolsGrid(511,511) As Boolean

'Access 255,255

If BoolGrid(255,255) Then

'I Found It to be True

End If
Regards - OHM

Crirus wrote:
Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a
particular point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in
my grid.

I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each
value y*512+x added to the array tells me that in p(x,y) I have value
True Drawback: Search if there is a value like y*512 +x in my
array can be
long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains,
Remove for adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how
much memory require

Anyway, I need the best compromise memory allocated - search for
value - set a value

Any advices?

I know I could test each one, just hope someone have allready done it
:)


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #3
I would think they are the same or very similar. I'm not actually sure how
to find out how much memory an individual object takes up on the heap, thats
a good question.

Regards OHM
Crirus wrote:
BoolGrid(511,511) require the same memoy as
myBitArray.Length(511*511)??
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message news:ux**************@tk2msftngp13.phx.gbl...
Why not

Dim BoolsGrid(511,511) As Boolean

'Access 255,255

If BoolGrid(255,255) Then

'I Found It to be True

End If
Regards - OHM

Crirus wrote:
Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a
particular point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in
my grid.

I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each
value y*512+x added to the array tells me that in p(x,y) I have
value True Drawback: Search if there is a value like y*512 +x
in my
array can be
long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains,
Remove for adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how
much memory require

Anyway, I need the best compromise memory allocated - search for
value - set a value

Any advices?

I know I could test each one, just hope someone have allready done
it :)


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #4
BitArray it may be better

Each 8 elements of a BitArray need a byte
How about Boolean?

Boolean variables are stored as 16-bit (2-byte) numbers... so I guess
BitArray fit better for big arrays of boolean values

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:us*************@TK2MSFTNGP11.phx.gbl...
I would think they are the same or very similar. I'm not actually sure how
to find out how much memory an individual object takes up on the heap, thats a good question.

Regards OHM
Crirus wrote:
BoolGrid(511,511) require the same memoy as
myBitArray.Length(511*511)??
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message news:ux**************@tk2msftngp13.phx.gbl...
Why not

Dim BoolsGrid(511,511) As Boolean

'Access 255,255

If BoolGrid(255,255) Then

'I Found It to be True

End If
Regards - OHM

Crirus wrote:
Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a
particular point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in
my grid.

I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each
value y*512+x added to the array tells me that in p(x,y) I have
value True Drawback: Search if there is a value like y*512 +x
in my
array can be
long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains,
Remove for adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how
much memory require

Anyway, I need the best compromise memory allocated - search for
value - set a value

Any advices?

I know I could test each one, just hope someone have allready done
it :)

--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #5
I must admit I didnt check the boolean storage, seems a bit over the top to
me.

Regards - OHM
Crirus wrote:
BitArray it may be better

Each 8 elements of a BitArray need a byte
How about Boolean?

Boolean variables are stored as 16-bit (2-byte) numbers... so I guess
BitArray fit better for big arrays of boolean values
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message news:us*************@TK2MSFTNGP11.phx.gbl...
I would think they are the same or very similar. I'm not actually
sure how to find out how much memory an individual object takes up
on the heap, thats a good question.

Regards OHM
Crirus wrote:
BoolGrid(511,511) require the same memoy as
myBitArray.Length(511*511)??
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message news:ux**************@tk2msftngp13.phx.gbl...
Why not

Dim BoolsGrid(511,511) As Boolean

'Access 255,255

If BoolGrid(255,255) Then

'I Found It to be True

End If
Regards - OHM

Crirus wrote:
> Hello
> I have 512x512 grid of booleans
> At a specific point in my application, I need to find out if a
> particular point in my grid have value true of false.
>
> Now I need a way to store the boolean value for each coordinates
> in my grid.
>
> I found some methods:
>
> 1. I could have a 512x512 BitArray Class something like P(x,y) ~
> myBitArray(y*512+x) = True
> A simple check will tell me what value is in a particular
> point Drawback: memory occupied without reason
>
> 2. Another way is to store only the true values in an array. Each
> value y*512+x added to the array tells me that in p(x,y) I have
> value True Drawback: Search if there is a value like y*512 +x
> in my
> array can be
> long, setting a new value means Redim Preserve the array and is
> time consumming, right?
>
> 3. I could use ArrayList with y*-512+x values and Add, Contains,
> Remove for adding, testing, setting a value.
> Drawback: have no iddea if is faster than the other ways or
> how much memory require
>
> Anyway, I need the best compromise memory allocated - search for
> value - set a value
>
> Any advices?
>
> I know I could test each one, just hope someone have allready done
> it :)

--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #6
totally different approach...
if you don't have a lot booleans being true (or false) you can maybe create
a collection that contains the "index" of the "small group" elements
index here would be y*512 + x

"Crirus" <Cr****@datagroup.ro> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a particular
point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in my grid.
I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each value
y*512+x added to the array tells me that in p(x,y) I have value True
Drawback: Search if there is a value like y*512 +x in my array can be
long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains, Remove for adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how much
memory require

Anyway, I need the best compromise memory allocated - search for value - set a value

Any advices?

I know I could test each one, just hope someone have allready done it :)

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #7
I considered that solution either.. still not sure how may of them whould
be...
And a redim each time a value is swithched ...hmmm, may be time consumming?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:eT**************@TK2MSFTNGP12.phx.gbl...
totally different approach...
if you don't have a lot booleans being true (or false) you can maybe create a collection that contains the "index" of the "small group" elements
index here would be y*512 + x

"Crirus" <Cr****@datagroup.ro> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a particular point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in my

grid.

I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each value
y*512+x added to the array tells me that in p(x,y) I have value True
Drawback: Search if there is a value like y*512 +x in my array can be long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains, Remove

for
adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how much
memory require

Anyway, I need the best compromise memory allocated - search for value -

set
a value

Any advices?

I know I could test each one, just hope someone have allready done it :)

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------


Nov 20 '05 #8
I was thinking about a collection not an array
so a redim is not needed...
for an ArrayList add, remove and contains methods can be used

"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
I considered that solution either.. still not sure how may of them whould
be...
And a redim each time a value is swithched ...hmmm, may be time consumming?
--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:eT**************@TK2MSFTNGP12.phx.gbl...
totally different approach...
if you don't have a lot booleans being true (or false) you can maybe

create
a collection that contains the "index" of the "small group" elements
index here would be y*512 + x

"Crirus" <Cr****@datagroup.ro> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
Hello
I have 512x512 grid of booleans
At a specific point in my application, I need to find out if a particular point in my grid have value true of false.

Now I need a way to store the boolean value for each coordinates in my

grid.

I found some methods:

1. I could have a 512x512 BitArray Class something like P(x,y) ~
myBitArray(y*512+x) = True
A simple check will tell me what value is in a particular point
Drawback: memory occupied without reason

2. Another way is to store only the true values in an array. Each value y*512+x added to the array tells me that in p(x,y) I have value True
Drawback: Search if there is a value like y*512 +x in my array can be long, setting a new value means Redim Preserve the array and is time
consumming, right?

3. I could use ArrayList with y*-512+x values and Add, Contains, Remove
for
adding, testing, setting a value.
Drawback: have no iddea if is faster than the other ways or how
much memory require

Anyway, I need the best compromise memory allocated - search for value - set
a value

Any advices?

I know I could test each one, just hope someone have allready done it

:)
--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------



Nov 20 '05 #9
yah, but how much memory require an ArrayList vs. array then? :)

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:ex**************@TK2MSFTNGP11.phx.gbl...
I was thinking about a collection not an array
so a redim is not needed...
for an ArrayList add, remove and contains methods can be used

"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
I considered that solution either.. still not sure how may of them whould
be...
And a redim each time a value is swithched ...hmmm, may be time consumming?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:eT**************@TK2MSFTNGP12.phx.gbl...
totally different approach...
if you don't have a lot booleans being true (or false) you can maybe

create
a collection that contains the "index" of the "small group" elements
index here would be y*512 + x

"Crirus" <Cr****@datagroup.ro> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
> Hello
> I have 512x512 grid of booleans
> At a specific point in my application, I need to find out if a

particular
> point in my grid have value true of false.
>
> Now I need a way to store the boolean value for each coordinates in my grid.
>
> I found some methods:
>
> 1. I could have a 512x512 BitArray Class something like P(x,y) ~
> myBitArray(y*512+x) = True
> A simple check will tell me what value is in a particular point
> Drawback: memory occupied without reason
>
> 2. Another way is to store only the true values in an array. Each value > y*512+x added to the array tells me that in p(x,y) I have value True
> Drawback: Search if there is a value like y*512 +x in my array
can be
> long, setting a new value means Redim Preserve the array and is time
> consumming, right?
>
> 3. I could use ArrayList with y*-512+x values and Add, Contains,

Remove for
> adding, testing, setting a value.
> Drawback: have no iddea if is faster than the other ways or how much > memory require
>
> Anyway, I need the best compromise memory allocated - search for value - set
> a value
>
> Any advices?
>
> I know I could test each one, just hope someone have allready done
it :) >
> --
> Cheers,
> Crirus
>
> ------------------------------
> If work were a good thing, the boss would take it all from you
>
> ------------------------------
>
>



Nov 20 '05 #10
On Wed, 14 Jan 2004 14:18:22 +0200, "Crirus" <Cr****@datagroup.ro>
wrote:
yah, but how much memory require an ArrayList vs. array then? :)


heres a little info i found on memory management between the two...

An array is a set of numbered items maintained contiguously in memory.
An array has a fixed size. So if you want to add an additional item to
an array, a new array must be created and all the items copied from
the old array into the new one. In vb.net that is done with the redim
statement. This operation is not particularly fast.

An arraylist is similar to an array, except that memory management of
a growing list is done for you. If you allocate an arraylist of 35
items, .NET actually allocates space for 64. When you add additional
items to the list, it fills up to 64 without any additional allocation
of memory. If you add a 65th item, it automatically allocates a new
arraylist with 128 spaces and copies the 64 items from the old
arraylist into the new one, then deallocates the memory for the old
one (which gets cleaned up on the next garbage collection).

So when you have a growing list, it means that you don't have to
manage the memory management issues of efficiently maintaining the
size of the list. There is some overhead to the arraylist, so if you
know the final size that you want the list to be ahead of time, you
are better off using an array. If you don't know the size it needs to
be, the arraylist is the better option.

lostdreamz
Nov 20 '05 #11
you can also define the allocated space when creating the arraylist

so if you know you will need max 200 elements, just create an arraylist of
200 elements...
if you stay under that limit a "resize" will never be done...
"lostdreamz" <yb***********@ubgznvy.pbz> wrote in message
news:ce********************************@4ax.com...
On Wed, 14 Jan 2004 14:18:22 +0200, "Crirus" <Cr****@datagroup.ro>
wrote:
yah, but how much memory require an ArrayList vs. array then? :)


heres a little info i found on memory management between the two...

An array is a set of numbered items maintained contiguously in memory.
An array has a fixed size. So if you want to add an additional item to
an array, a new array must be created and all the items copied from
the old array into the new one. In vb.net that is done with the redim
statement. This operation is not particularly fast.

An arraylist is similar to an array, except that memory management of
a growing list is done for you. If you allocate an arraylist of 35
items, .NET actually allocates space for 64. When you add additional
items to the list, it fills up to 64 without any additional allocation
of memory. If you add a 65th item, it automatically allocates a new
arraylist with 128 spaces and copies the 64 items from the old
arraylist into the new one, then deallocates the memory for the old
one (which gets cleaned up on the next garbage collection).

So when you have a growing list, it means that you don't have to
manage the memory management issues of efficiently maintaining the
size of the list. There is some overhead to the arraylist, so if you
know the final size that you want the list to be ahead of time, you
are better off using an array. If you don't know the size it needs to
be, the arraylist is the better option.

lostdreamz

Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Neil | last post by:
I just resolved a strange situation I was having with an ODBC linked SQL 7 view in an Access 2000 MDB file, and I'm trying to get some understanding as to what happened. The linked view was...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: AC Slater | last post by:
Whats the simplest way to change a single stored procedures query optimization level? In UDB8 that is. /F
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
3
by: Dmitry Jouravlev | last post by:
Hi, I have a number of C++ solutions in Visual Studio .NET and when i compile them using "Whole Program Optimization", certain projects report a LNK1171 error saying that c2.dll could not be...
19
by: Jim West | last post by:
The execution speed of the following code is dramatically faster if I declare some arrays globally rather than locally. That is FOO a, b, c; void bar() { ... } runs much faster (up to...
10
by: SzH | last post by:
The code below demonstrates that the copy constructor of moo is not called on the first line of main. In spite of this, g++ (version 4.1.2) refuses to compile it if I make the copy constructor...
3
wiredwizard
by: wiredwizard | last post by:
So does my site need optimization or marketing? (my response to a recent email from a gentleman asking whether he should optimize or market his website and I was wondering what others think) ...
34
by: jacob navia | last post by:
Hi I am adding an optimization to lcc-win: sqrt(2.0) will provoke now that the constant 1.4142... etc will be generated instead of generating an actual call. Details: -------
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.