[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

9/24/2011 11:12:00 PM

Project with Forms, Classes, Modules and a UserControl.
I ReDim Preserve a string array in the UserControl and at some point I
get an out of memory error.

1) does this apply to the whole project? I.E. is memory space
allocated for each or some elements: Form, Module, Class etc. How much
max per?

2) How can I watch memory usage prior to running out?

3) What is the best way to get more memory for an array that the
UserControl needs? Public the array from a Module that only holds this
array? Or?

4) If I cannot get enough memory from VB components (.frm, .bas etc),
what is the fastest way to get memory I/O space from virtual memory?
Open Binary or Random file all the time? RAM drive?
Since I am storing and retrieving strings and the they are variable
length so ...? And RAM drive would be faster, yes?

5) Been trying to find RAM drive but so far no luck. Maybe need
different terminology to search for?


24 Answers

Mike Williams

9/25/2011 1:30:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:j5lo4h$dmq$1@speranza.aioe.org...

> Project with Forms, Classes, Modules and a UserControl.
> I ReDim Preserve a string array in the UserControl and at
> some point I get an out of memory error.
> 1) does this apply to the whole project? I.E. is memory
> space allocated for each or some elements: Form, Module,
> Class etc. How much max per?

On Win32 systems your VB6 program can normally use up to 2GB of memory
regardless of how much real RAM you have (unless you have been messing with
your Windows Page File limit and you have only a small amount of RAM). On 64
bit versions of Windows this 2GB limit does not normally apply to 64 bit
programs, but as far as I know it still applies to 32 bit programs, such as
VB6. As far as your VB6 program is concerned the 2GB is the total maximum
for your program, regardless of where it is used (in one or more of your
User Controls or somewhere else). You can of course additionally use as much
space as is available to store stuff on your disk drive, but before you look
at anything else I would suggest that you look at how much memory you
actually are using. Are you really using something approaching 2GB for your
Strings (which will take two bytes per character), or is some of your code
leaking memory? Have you checked this? It seems a lot.

Mike



Nigel Bufton

9/26/2011 7:00:00 AM

0

BeeJ submitted this idea :
> Project with Forms, Classes, Modules and a UserControl.
> I ReDim Preserve a string array in the UserControl and at some point I get an
> out of memory error.
>
> 1) does this apply to the whole project? I.E. is memory space allocated for
> each or some elements: Form, Module, Class etc. How much max per?
>
> 2) How can I watch memory usage prior to running out?
>
> 3) What is the best way to get more memory for an array that the UserControl
> needs? Public the array from a Module that only holds this array? Or?
>
> 4) If I cannot get enough memory from VB components (.frm, .bas etc), what is
> the fastest way to get memory I/O space from virtual memory? Open Binary or
> Random file all the time? RAM drive?
> Since I am storing and retrieving strings and the they are variable length so
> ...? And RAM drive would be faster, yes?
>
> 5) Been trying to find RAM drive but so far no luck. Maybe need different
> terminology to search for?

"Out of memory" means that Windows cannot allocate a large enough contiguous
chunk from the memory available. Frequently this means a memory fragmentation
issue - i.e., you can have enough available memory in total, but not enough
in a contiguous chunk.

Nigel


Mike Williams

9/26/2011 12:37:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:j5oh26$ens$1@speranza.aioe.org...

> The code snippet above will help with this next memory overrun
> problem but it will take me another few days to get to it.

Well, like Nigel said, knowing how much memory you've got left is not quite
the same as knowing whether you are going to get a memory error. It just
tells you how much memory you have left, not how big the largest contiguous
block might be. I posted it simply because you asked how to do such a thing.
In your particular case (redimensioning arrays of strings and then
populating the added elements with string data), the smaller the individual
strings are the more likely you are to get a memory error whilst there is
actually still a significant amount of memory left. That's because it is the
list of string pointers for the array which need a contiguous block of
memory, rather than the string data itself, and the smaller the strings are
then the larger the list of pointers will be by the time you start getting
near your memory limits. In such cases you are likely to get an "Out of
memory" error, and get it whilst there is actually a significant amount of
memory left, whereas doing a similar thing with very large strings you are
more likely to get an "Out of String Space" error and get fairly close to
the memory limit. Having said that, if you are getting anywhere near the
memory limits in your program then perhaps it is time to look again at what
you are doing and to see if it can be done in a less memory intensive way.

> I need to wind up with two arrays that are blank in one with a
> mismatch with the other (the other retains the value) and a same
> values in both when they match.

Well, that's about as clear as mud ;-) Perhaps it is time to give an
outline of what you are actually doing (the reason behind it all) rather
than the details of how you are doing it. For example, in one of your posts
I think you said that you were loading and sorting very large arrays of
Strings, each of which is the string representation of an integer? I don't
know where you are pulling this string data from, nor why it is in that
particular format, but surely you don't need to hold it in that format in
your arrays? Why can't you convert to integers as you load it and then
convert back to string representation after you have analyzed and sorted it
or whatever and when you want to save it back? Why can't you work like that?

> RAM drive? Since I am storing and retrieving strings and
> the they are variable length so ...? And RAM drive would
> be faster, yes?

It depends on the machine. On many machines a RAM drive can actually be self
defeating. It's horses for courses.

Mike



BeeJ

9/26/2011 10:35:00 PM

0

We got confused somewhere.

For this particular app I am sorting Drive:\Path\Filename.Ext from two
different sources, say the C: and D: drives.
I sort each so that they can line up next to each other in a way that I
can then cycle down through both lists and see were the differences
are.
I wind up with two new lists where there are blanks where one side does
not match the other and opposing matching elements have the same
filename string.

List 1 List 2
C:\A\X.EXE D:\A\A.EXE
C:\A\Y.EXE D:\A\Y.EXE
C:\A\Z.EXE

The new lists would look like and show in the virtual List report as
. D:\A\A.EXE
C:\A\X.EXE .
C:\A\Y.EXE D:\A\Y.EXE
C:\A\Z.EXE .

Of course it is more complex with many subfolders.

The trick is getting the correct key and "merge" the lists.

I wrote an app that does just this but I am enhancing it by:
Status Working! - changing a flex grid to a virtual List Report
(bigger, faster)
and having to fix the virtual List report as well
Status Working! - changing a slow sort to one of the new fast UDT
sorts.
Status Working! - changing the file find to a faster FindFirst with
grabs on the other file data (previous code re-accessed the file for
size, dates, attributs etc).

I expect to at least double the speed from the old app as current
testing shows.
Also, the user interface is now less problematic.
It has automatic drive change notification and simplified user
interface.

It is all working except for the new list creation (that I have done
before but must have messed up the code a little when I injected it
into the new app). Oh well.

I am inserting the memory monitor code now and hope to get in a few
runs soon and report back on that aspect.


BeeJ

9/27/2011 1:35:00 AM

0

Yikes. Need more RAM???? RAM Drive or File I/O (yuck).
So my arrays are getting too big, looks like.
Or I have a code problem.
Need to dive in deeper.
When I get the error, I am trying to allocate only what I need in a
ReDim Preserve if a Type Array.
There are three different Type Arrays ReDim Preserve in a row and the
first one makes it through.
The second one kills it and of course never gets to the third.

Nice memory available snippet so maybe I can search for the big bang or
in this case the big crunch.

2011.09.26 18:07:53 V1.0.0 Refresh Available memory 2,007,793,664
bytes
2011.09.26 18:10:01 V1.0.0 Acquire Sort Left Available memory
1,944,616,960 bytes
2011.09.26 18:10:01 V1.0.0 Acquire Sort Right Available memory
1,944,616,960 bytes
2011.09.26 18:10:37 V1.0.0 AddItem: 7:Out of memory
2011.09.26 18:26:42 V1.0.0 MergeListsErr Available memory 160,374,784
bytes
2011.09.26 18:26:42 V1.0.0 Merge - Processed 68589 entries out of
103406
2011.09.26 18:27:05 V1.0.0 Merge Available memory 160,358,400 bytes


Mike Williams

9/27/2011 11:07:00 AM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:j5r98o$kmh$1@speranza.aioe.org...

> Yikes. Need more RAM???? RAM Drive or File I/O (yuck).

Is your code just for yourself, or for distribution to others?

Mike


Mike Williams

9/27/2011 12:03:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:j5qumu$tg3$1@speranza.aioe.org...

> For this particular app I am sorting Drive:\Path\Filename.Ext
> from two different sources, say the C: and D: drives.
> I sort each so that they can line up next to each other in a
> way that I can then cycle down through both lists and see
> were the differences are . . .
> List 1 List 2
> C:\A\X.EXE D:\A\A.EXE
> C:\A\Y.EXE D:\A\Y.EXE
> C:\A\Z.EXE
> The new lists would look like and show . . . as
> . D:\A\A.EXE
> C:\A\X.EXE .
> C:\A\Y.EXE D:\A\Y.EXE
> C:\A\Z.EXE .

Holding all this data in memory all at the same time is what is leading to
most of your problems, and it is probably not the way others might do it,
but if you really do want to hold it all in memory then have you considered
holding just the filenames themselves in your arrays, with any specific
array holding the filenames only for a specific folder path, rather than
storing the full path and name for every single file, as it appears you are
currently doing? This would save a lot of memory.

Mike



Jason Keats

9/27/2011 12:18:00 PM

0

NigelBufton wrote:
> BeeJ submitted this idea :
>> Project with Forms, Classes, Modules and a UserControl.
>> I ReDim Preserve a string array in the UserControl and at some point I get an
>> out of memory error.
>>
>> 1) does this apply to the whole project? I.E. is memory space allocated for
>> each or some elements: Form, Module, Class etc. How much max per?
>>
>> 2) How can I watch memory usage prior to running out?
>>
>> 3) What is the best way to get more memory for an array that the UserControl
>> needs? Public the array from a Module that only holds this array? Or?
>>
>> 4) If I cannot get enough memory from VB components (.frm, .bas etc), what is
>> the fastest way to get memory I/O space from virtual memory? Open Binary or
>> Random file all the time? RAM drive?
>> Since I am storing and retrieving strings and the they are variable length so
>> ...? And RAM drive would be faster, yes?
>>
>> 5) Been trying to find RAM drive but so far no luck. Maybe need different
>> terminology to search for?
>
> "Out of memory" means that Windows cannot allocate a large enough contiguous
> chunk from the memory available. Frequently this means a memory fragmentation
> issue - i.e., you can have enough available memory in total, but not enough
> in a contiguous chunk.
>

Or, according to http://support.microsoft.com..., it could mean
that "a 64K segment boundary was encountered".

So, it could mean that your modules/forms/procedures are too big, rather
than being short of RAM.

(nobody)

9/27/2011 12:38:00 PM

0

"Jason Keats" <jkeats@melbpcDeleteThis.org.au> wrote in message
news:j5sesp$f17$1@speranza.aioe.org...
> Or, according to http://support.microsoft.com..., it could mean
> that "a 64K segment boundary was encountered".
>
> So, it could mean that your modules/forms/procedures are too big, rather
> than being short of RAM.

That article is for VBA, and very old versions in the Windows 3.1 era. MSKB
by default auto hides the "Applies to" list, so you have to click on the "+"
sign. Here is the Applies to list:

Microsoft Excel 95 Standard Edition
Microsoft Excel 5.0c
Microsoft Excel 5.0 Standard Edition
Microsoft Excel 5.0a for Macintosh
Microsoft Project 4.0 Standard Edition
Microsoft Project 4.1 Standard Edition


Jason Keats

9/27/2011 1:19:00 PM

0

Nobody wrote:
> "Jason Keats"<jkeats@melbpcDeleteThis.org.au> wrote in message
> news:j5sesp$f17$1@speranza.aioe.org...
>> Or, according to http://support.microsoft.com..., it could mean
>> that "a 64K segment boundary was encountered".
>>
>> So, it could mean that your modules/forms/procedures are too big, rather
>> than being short of RAM.
>
> That article is for VBA, and very old versions in the Windows 3.1 era. MSKB
> by default auto hides the "Applies to" list, so you have to click on the "+"
> sign. Here is the Applies to list:
>
> Microsoft Excel 95 Standard Edition
> Microsoft Excel 5.0c
> Microsoft Excel 5.0 Standard Edition
> Microsoft Excel 5.0a for Macintosh
> Microsoft Project 4.0 Standard Edition
> Microsoft Project 4.1 Standard Edition
>
>

Fair enough.

I thought I read somewhere that large modules could cause an out of
memory exception - so I foolishly went looking for a link to prove it. I
obviously didn't read it carefully.

Sorry for spreading misinformation.