Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Array Memory Size

Hello All,

I'm hoping to find a Win32 API which will provide me the memory size
of a safe array dimmed in VBA.

Here's what I am trying to solve...

I currently calculate a moving average of the last x elements stored
within an array. Step one is to find the last element used within the
array, for which I currently use a self-written binary search. Next,
I use a Win32 api to copy the segment of memory (CopyMemory)
containing the elements I want to average into another array so that I
can execute:

Avg = Application.Average(arrayTwo)

The slowest part of this oppoeration is the binary search. So, I was
hoping to get the size of the memory used by the array and then devide
the returned value by the number of bytes per element to determin the
number of the last element used within the array. (Please note,
Ubound only gives me the upper bound of the array, not the last used
element in the array).

Any ideas??

Thanks!

Trip
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default Array Memory Size

Start with UBOUND position and iterate backwards to find the last used
element?

--
Jim
"Trip" wrote in message
...
| Hello All,
|
| I'm hoping to find a Win32 API which will provide me the memory size
| of a safe array dimmed in VBA.
|
| Here's what I am trying to solve...
|
| I currently calculate a moving average of the last x elements stored
| within an array. Step one is to find the last element used within the
| array, for which I currently use a self-written binary search. Next,
| I use a Win32 api to copy the segment of memory (CopyMemory)
| containing the elements I want to average into another array so that I
| can execute:
|
| Avg = Application.Average(arrayTwo)
|
| The slowest part of this oppoeration is the binary search. So, I was
| hoping to get the size of the memory used by the array and then devide
| the returned value by the number of bytes per element to determin the
| number of the last element used within the array. (Please note,
| Ubound only gives me the upper bound of the array, not the last used
| element in the array).
|
| Any ideas??
|
| Thanks!
|
| Trip


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Array Memory Size

Binary search on a sorted array should be faster than using
Application.Average, so I suspect there is something else happening.

Also its probably faster to just directly compute the average by looping on
the array rather than passing a subset to an Excel worksheet function.
The time taken to do both these operations will usually be insignificant
compared to the time taken to get the data into a variant array in the first
place.

Can you post some code, along with an indication of how many microseconds
you need this to take?

regards
Charles
_________________________________________
FastExcel 2.3
Name Manager 4.0
http://www.DecisionModels.com

"Trip" wrote in message
...
Hello All,

I'm hoping to find a Win32 API which will provide me the memory size
of a safe array dimmed in VBA.

Here's what I am trying to solve...

I currently calculate a moving average of the last x elements stored
within an array. Step one is to find the last element used within the
array, for which I currently use a self-written binary search. Next,
I use a Win32 api to copy the segment of memory (CopyMemory)
containing the elements I want to average into another array so that I
can execute:

Avg = Application.Average(arrayTwo)

The slowest part of this oppoeration is the binary search. So, I was
hoping to get the size of the memory used by the array and then devide
the returned value by the number of bytes per element to determin the
number of the last element used within the array. (Please note,
Ubound only gives me the upper bound of the array, not the last used
element in the array).

Any ideas??

Thanks!

Trip



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Array Memory Size

Trip wrote:. . .
I currently calculate a moving average of the last x elements stored
within an array. Step one is to find the last element used within the
array, for which I currently use a self-written binary search. Next,
I use a Win32 api to copy the segment of memory (CopyMemory)
containing the elements I want to average into another array so that I
can execute:

Avg = Application.Average(arrayTwo)

The slowest part of this oppoeration is the binary search. . . .

Any ideas??


If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook, you can
get the index number of the last used element with

UBound(arrayOne) - LBound(arrayOne) + 1 - ArrayCountIf(arrayOne)

I have no idea how it compares in speed to your binary search.

Alan Beban
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Array Memory Size

How come you don't know the last used element in the array?
What/who is filling that array?
If it is your code you should be able to keep track of that.

RBS


"Trip" wrote in message
...
Hello All,

I'm hoping to find a Win32 API which will provide me the memory size
of a safe array dimmed in VBA.

Here's what I am trying to solve...

I currently calculate a moving average of the last x elements stored
within an array. Step one is to find the last element used within the
array, for which I currently use a self-written binary search. Next,
I use a Win32 api to copy the segment of memory (CopyMemory)
containing the elements I want to average into another array so that I
can execute:

Avg = Application.Average(arrayTwo)

The slowest part of this oppoeration is the binary search. So, I was
hoping to get the size of the memory used by the array and then devide
the returned value by the number of bytes per element to determin the
number of the last element used within the array. (Please note,
Ubound only gives me the upper bound of the array, not the last used
element in the array).

Any ideas??

Thanks!

Trip




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Array Memory Size

Ahhh, beautiful! Thanks!

On Dec 20, 2:41 pm, Alan Beban wrote:
Trip wrote:. . .
I currently calculate a moving average of the last x elements stored
within anarray. Step one is to find the last element used within the
array, for which I currently use a self-written binary search. Next,
I use a Win32 api to copy the segment ofmemory(CopyMemory)
containing the elements I want to average into anotherarrayso that I
can execute:


Avg = Application.Average(arrayTwo)


The slowest part of this oppoeration is the binary search. . . .


Any ideas??


If the functions in the freely downloadable file athttp://home.pacbell.net/bebanare available to your workbook, you can
get the index number of the last used element with

UBound(arrayOne) - LBound(arrayOne) + 1 - ArrayCountIf(arrayOne)

I have no idea how it compares in speed to your binary search.

Alan Beban


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Array Memory Size

Ooops, I spoke too soon. I reviewed the code of ArrayCountIf and it
actually loops through the entire array. This would be much slower
than a binary search. Good idea though. Thanks!

Trip

On Dec 20, 7:43 pm, Trip wrote:
Ahhh, beautiful! Thanks!

On Dec 20, 2:41 pm, Alan Beban wrote:



Trip wrote:. . .
I currently calculate a moving average of the last x elements stored
within anarray. Step one is to find the last element used within the
array, for which I currently use a self-written binary search. Next,
I use a Win32 api to copy the segment ofmemory(CopyMemory)
containing the elements I want to average into anotherarrayso that I
can execute:


Avg = Application.Average(arrayTwo)


The slowest part of this oppoeration is the binary search. . . .


Any ideas??


If the functions in the freely downloadable file athttp://home.pacbell.net/bebanareavailable to your workbook, you can
get the index number of the last used element with


UBound(arrayOne) - LBound(arrayOne) + 1 - ArrayCountIf(arrayOne)


I have no idea how it compares in speed to your binary search.


Alan Beban- Hide quoted text -


- Show quoted text -


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Array Memory Size

Too bad your array is not a String array... getting the index of the last
used element is a one-liner for that type of array.

LastUsedIndex = UBound(Split(Trim(Replace(Replace(Join(MyArray, _
Chr$(0)), " ", Chr$(1)), Chr$(0), " "))))

Unfortunately, you can't use the same trick on a numeric array.

Rick


"Trip" wrote in message
...
Hello All,

I'm hoping to find a Win32 API which will provide me the memory size
of a safe array dimmed in VBA.

Here's what I am trying to solve...

I currently calculate a moving average of the last x elements stored
within an array. Step one is to find the last element used within the
array, for which I currently use a self-written binary search. Next,
I use a Win32 api to copy the segment of memory (CopyMemory)
containing the elements I want to average into another array so that I
can execute:

Avg = Application.Average(arrayTwo)

The slowest part of this oppoeration is the binary search. So, I was
hoping to get the size of the memory used by the array and then devide
the returned value by the number of bytes per element to determin the
number of the last element used within the array. (Please note,
Ubound only gives me the upper bound of the array, not the last used
element in the array).

Any ideas??

Thanks!

Trip


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory and File Size Management MMcCullough Excel Discussion (Misc queries) 12 August 12th 06 01:48 AM
Memory and File Size Jim May Excel Discussion (Misc queries) 3 June 28th 06 07:44 PM
Size/memory limitations for vlookup fixed in the new Excel? Martin Miller Excel Discussion (Misc queries) 2 June 27th 06 08:49 PM
Displaying the size of the dataset currently in memory [email protected] Excel Programming 0 April 16th 06 02:45 PM
xls file size / memory errors Stuart Bazzard Excel Programming 2 April 26th 04 11:28 AM


All times are GMT +1. The time now is 07:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"