If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

VB Arrays and memory allocation

I wrote a while back asking about an appication error.
the error was something like:
the instruction at 0x... references memory at
0x... the instruction could not be 'written'.

I get this error sometimes, other times the system freezes,
and other times it works fine. I still don't know why.

VB handles memory management and I am not using API calls, so theoretically

everything should work (I don't really know much about how VB
handles memory).

Is it possible that the problem is that I have very large arrays
that periodically need to be redimensioned. Some of my arrays
are in user defined types, others are in classes and std_modules.
Array sizes can be greater than 100,000. Some can be nested within
other arrays or arrays of UDTs.

Redimensioning can cause arrays to be copied and written elsewhere
(true?). If I have complicated data structures, is it possible
that some error occurs such that VBs pointers no longer point
to the correct position in memory? Does VB have a garbage collector?
If not, is it possible that given the size of my arrays, the
system freezes after a number of hours running and fragmenting
heap memory?

Re: VB Arrays and memory allocation

Hi Brian,

I would suspect that one of the dynamic arrays inside the UDT is not
dimensioned.

"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
news:394f7606$1@news.devx.com...
>
> Hi,
>
> I wrote a while back asking about an appication error.
> the error was something like:
> the instruction at 0x... references memory at
> 0x... the instruction could not be 'written'.
>
> I get this error sometimes, other times the system freezes,
> and other times it works fine. I still don't know why.
>
> VB handles memory management and I am not using API calls, so
theoretically
>
> everything should work (I don't really know much about how VB
> handles memory).
>
> Is it possible that the problem is that I have very large arrays
> that periodically need to be redimensioned. Some of my arrays
> are in user defined types, others are in classes and std_modules.
> Array sizes can be greater than 100,000. Some can be nested within
> other arrays or arrays of UDTs.
>
> Redimensioning can cause arrays to be copied and written elsewhere
> (true?). If I have complicated data structures, is it possible
> that some error occurs such that VBs pointers no longer point
> to the correct position in memory? Does VB have a garbage collector?
> If not, is it possible that given the size of my arrays, the
> system freezes after a number of hours running and fragmenting
> heap memory?
>
> Thanks,
>
> Brian

Re: VB Arrays and memory allocation

Hi Brian,

I would suspect that one of the dynamic arrays inside the UDT is not
dimensioned.

"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
news:394f7606$1@news.devx.com...
>
> Hi,
>
> I wrote a while back asking about an appication error.
> the error was something like:
> the instruction at 0x... references memory at
> 0x... the instruction could not be 'written'.
>
> I get this error sometimes, other times the system freezes,
> and other times it works fine. I still don't know why.
>
> VB handles memory management and I am not using API calls, so
theoretically
>
> everything should work (I don't really know much about how VB
> handles memory).
>
> Is it possible that the problem is that I have very large arrays
> that periodically need to be redimensioned. Some of my arrays
> are in user defined types, others are in classes and std_modules.
> Array sizes can be greater than 100,000. Some can be nested within
> other arrays or arrays of UDTs.
>
> Redimensioning can cause arrays to be copied and written elsewhere
> (true?). If I have complicated data structures, is it possible
> that some error occurs such that VBs pointers no longer point
> to the correct position in memory? Does VB have a garbage collector?
> If not, is it possible that given the size of my arrays, the
> system freezes after a number of hours running and fragmenting
> heap memory?
>
> Thanks,
>
> Brian

Re: VB Arrays and memory allocation

Hi Bill,

shouldn't that give me an error message of "subscript out of range"
or something? Also, it usually works for many hours before
crashing on me.

"Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
>Hi Brian,
>
>I would suspect that one of the dynamic arrays inside the UDT is not
>dimensioned.
>
>
>"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>news:394f7606$1@news.devx.com...
>>
>> Hi,
>>
>> I wrote a while back asking about an appication error.
>> the error was something like:
>> the instruction at 0x... references memory at
>> 0x... the instruction could not be 'written'.
>>
>> I get this error sometimes, other times the system freezes,
>> and other times it works fine. I still don't know why.
>>
>> VB handles memory management and I am not using API calls, so
>theoretically
>>
>> everything should work (I don't really know much about how VB
>> handles memory).
>>
>> Is it possible that the problem is that I have very large arrays
>> that periodically need to be redimensioned. Some of my arrays
>> are in user defined types, others are in classes and std_modules.
>> Array sizes can be greater than 100,000. Some can be nested within
>> other arrays or arrays of UDTs.
>>
>> Redimensioning can cause arrays to be copied and written elsewhere
>> (true?). If I have complicated data structures, is it possible
>> that some error occurs such that VBs pointers no longer point
>> to the correct position in memory? Does VB have a garbage collector?
>> If not, is it possible that given the size of my arrays, the
>> system freezes after a number of hours running and fragmenting
>> heap memory?
>>
>> Thanks,
>>
>> Brian
>
>

Re: VB Arrays and memory allocation

Hi Bill,

shouldn't that give me an error message of "subscript out of range"
or something? Also, it usually works for many hours before
crashing on me.

"Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
>Hi Brian,
>
>I would suspect that one of the dynamic arrays inside the UDT is not
>dimensioned.
>
>
>"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>news:394f7606$1@news.devx.com...
>>
>> Hi,
>>
>> I wrote a while back asking about an appication error.
>> the error was something like:
>> the instruction at 0x... references memory at
>> 0x... the instruction could not be 'written'.
>>
>> I get this error sometimes, other times the system freezes,
>> and other times it works fine. I still don't know why.
>>
>> VB handles memory management and I am not using API calls, so
>theoretically
>>
>> everything should work (I don't really know much about how VB
>> handles memory).
>>
>> Is it possible that the problem is that I have very large arrays
>> that periodically need to be redimensioned. Some of my arrays
>> are in user defined types, others are in classes and std_modules.
>> Array sizes can be greater than 100,000. Some can be nested within
>> other arrays or arrays of UDTs.
>>
>> Redimensioning can cause arrays to be copied and written elsewhere
>> (true?). If I have complicated data structures, is it possible
>> that some error occurs such that VBs pointers no longer point
>> to the correct position in memory? Does VB have a garbage collector?
>> If not, is it possible that given the size of my arrays, the
>> system freezes after a number of hours running and fragmenting
>> heap memory?
>>
>> Thanks,
>>
>> Brian
>
>

Re: VB Arrays and memory allocation

It should, but I wouldn't rely on it.. Do you have DoEvents in your code or
is it possible that your code can be reading from an array in a loop and yet
Redim it ?

Also do you actually know the line of code that causes the failure, such as
will it fail when run from IDE ? (or put in line numbers and use the Erl
function to get the line number.. you will need error handlers for virtually
every function/sub.)

"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
news:394f8ac7$1@news.devx.com...
>
> Hi Bill,
>
> shouldn't that give me an error message of "subscript out of range"
> or something? Also, it usually works for many hours before
> crashing on me.
>
>
> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
> >Hi Brian,
> >
> >I would suspect that one of the dynamic arrays inside the UDT is not
> >dimensioned.
> >
> >
> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
> >news:394f7606$1@news.devx.com...
> >>
> >> Hi,
> >>
> >> I wrote a while back asking about an appication error.
> >> the error was something like:
> >> the instruction at 0x... references memory at
> >> 0x... the instruction could not be 'written'.
> >>
> >> I get this error sometimes, other times the system freezes,
> >> and other times it works fine. I still don't know why.
> >>
> >> VB handles memory management and I am not using API calls, so
> >theoretically
> >>
> >> everything should work (I don't really know much about how VB
> >> handles memory).
> >>
> >> Is it possible that the problem is that I have very large arrays
> >> that periodically need to be redimensioned. Some of my arrays
> >> are in user defined types, others are in classes and std_modules.
> >> Array sizes can be greater than 100,000. Some can be nested within
> >> other arrays or arrays of UDTs.
> >>
> >> Redimensioning can cause arrays to be copied and written elsewhere
> >> (true?). If I have complicated data structures, is it possible
> >> that some error occurs such that VBs pointers no longer point
> >> to the correct position in memory? Does VB have a garbage collector?
> >> If not, is it possible that given the size of my arrays, the
> >> system freezes after a number of hours running and fragmenting
> >> heap memory?
> >>
> >> Thanks,
> >>
> >> Brian
> >
> >
>

Re: VB Arrays and memory allocation

It should, but I wouldn't rely on it.. Do you have DoEvents in your code or
is it possible that your code can be reading from an array in a loop and yet
Redim it ?

Also do you actually know the line of code that causes the failure, such as
will it fail when run from IDE ? (or put in line numbers and use the Erl
function to get the line number.. you will need error handlers for virtually
every function/sub.)

"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
news:394f8ac7$1@news.devx.com...
>
> Hi Bill,
>
> shouldn't that give me an error message of "subscript out of range"
> or something? Also, it usually works for many hours before
> crashing on me.
>
>
> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
> >Hi Brian,
> >
> >I would suspect that one of the dynamic arrays inside the UDT is not
> >dimensioned.
> >
> >
> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
> >news:394f7606$1@news.devx.com...
> >>
> >> Hi,
> >>
> >> I wrote a while back asking about an appication error.
> >> the error was something like:
> >> the instruction at 0x... references memory at
> >> 0x... the instruction could not be 'written'.
> >>
> >> I get this error sometimes, other times the system freezes,
> >> and other times it works fine. I still don't know why.
> >>
> >> VB handles memory management and I am not using API calls, so
> >theoretically
> >>
> >> everything should work (I don't really know much about how VB
> >> handles memory).
> >>
> >> Is it possible that the problem is that I have very large arrays
> >> that periodically need to be redimensioned. Some of my arrays
> >> are in user defined types, others are in classes and std_modules.
> >> Array sizes can be greater than 100,000. Some can be nested within
> >> other arrays or arrays of UDTs.
> >>
> >> Redimensioning can cause arrays to be copied and written elsewhere
> >> (true?). If I have complicated data structures, is it possible
> >> that some error occurs such that VBs pointers no longer point
> >> to the correct position in memory? Does VB have a garbage collector?
> >> If not, is it possible that given the size of my arrays, the
> >> system freezes after a number of hours running and fragmenting
> >> heap memory?
> >>
> >> Thanks,
> >>
> >> Brian
> >
> >
>

Re: VB Arrays and memory allocation

Hi Bill,
>It should, but I wouldn't rely on it.. Do you have DoEvents in your code
or
>is it possible that your code can be reading from an array in a loop and
yet
>Redim it ?

Yes, I have DoEvents in my code. What is the potential consequences of that?
I'll check to see whether I am reading from an array in a loop and ReDiming
it.
I seem to remember having a problem with my arrays being
temporarily locked in the compiled version (not in the IDE).
The only way I could fix that was to not redim the problem
array at all during the program (and consequently setting aside
a more than necessary memory).

when you say reading from an array in a loop and rediming it do you mean

for x=1 to 10
func y(x)
redim preserve y(n)
next x

where func is a function
or something like that? or where y is redimed in func?
>
>Also do you actually know the line of code that causes the failure, such
as
>will it fail when run from IDE ? (or put in line numbers and use the Erl
>function to get the line number.. you will need error handlers for virtually
>every function/sub.)
>

I don't know the exact line of code, but I know some of the functions it
occurs
in (not the nested functions though). I thought it didn't fail in
the IDE before, but I have found that it does (at least with
the changes that I have made recently). The program crashes in more than
one function. The IDE crashes with it (i.e., I can't use VBs great
debugging abilities). Error handlers do not keep the entire IDE from crashing.
I tried writing the current function to a log file
to find where the program crashes. Outputting to file at each function
slows the program down greatly (especially given it takes hours
to days for the program to crash). Is there another way?

I'm also going to try removing all redim statements for large
arrays from my program and set aside sufficient memory for them
at the beginning and see what happens.

Thanks Bill,

Brian
>
>"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>news:394f8ac7$1@news.devx.com...
>>
>> Hi Bill,
>>
>> shouldn't that give me an error message of "subscript out of range"
>> or something? Also, it usually works for many hours before
>> crashing on me.
>>
>>
>> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
>> >Hi Brian,
>> >
>> >I would suspect that one of the dynamic arrays inside the UDT is not
>> >dimensioned.
>> >
>> >
>> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>> >news:394f7606$1@news.devx.com...
>> >>
>> >> Hi,
>> >>
>> >> I wrote a while back asking about an appication error.
>> >> the error was something like:
>> >> the instruction at 0x... references memory at
>> >> 0x... the instruction could not be 'written'.
>> >>
>> >> I get this error sometimes, other times the system freezes,
>> >> and other times it works fine. I still don't know why.
>> >>
>> >> VB handles memory management and I am not using API calls, so
>> >theoretically
>> >>
>> >> everything should work (I don't really know much about how VB
>> >> handles memory).
>> >>
>> >> Is it possible that the problem is that I have very large arrays
>> >> that periodically need to be redimensioned. Some of my arrays
>> >> are in user defined types, others are in classes and std_modules.
>> >> Array sizes can be greater than 100,000. Some can be nested within
>> >> other arrays or arrays of UDTs.
>> >>
>> >> Redimensioning can cause arrays to be copied and written elsewhere
>> >> (true?). If I have complicated data structures, is it possible
>> >> that some error occurs such that VBs pointers no longer point
>> >> to the correct position in memory? Does VB have a garbage collector?
>> >> If not, is it possible that given the size of my arrays, the
>> >> system freezes after a number of hours running and fragmenting
>> >> heap memory?
>> >>
>> >> Thanks,
>> >>
>> >> Brian
>> >
>> >
>>
>
>

Re: VB Arrays and memory allocation

Hi Bill,
>It should, but I wouldn't rely on it.. Do you have DoEvents in your code
or
>is it possible that your code can be reading from an array in a loop and
yet
>Redim it ?

Yes, I have DoEvents in my code. What is the potential consequences of that?
I'll check to see whether I am reading from an array in a loop and ReDiming
it.
I seem to remember having a problem with my arrays being
temporarily locked in the compiled version (not in the IDE).
The only way I could fix that was to not redim the problem
array at all during the program (and consequently setting aside
a more than necessary memory).

when you say reading from an array in a loop and rediming it do you mean

for x=1 to 10
func y(x)
redim preserve y(n)
next x

where func is a function
or something like that? or where y is redimed in func?
>
>Also do you actually know the line of code that causes the failure, such
as
>will it fail when run from IDE ? (or put in line numbers and use the Erl
>function to get the line number.. you will need error handlers for virtually
>every function/sub.)
>

I don't know the exact line of code, but I know some of the functions it
occurs
in (not the nested functions though). I thought it didn't fail in
the IDE before, but I have found that it does (at least with
the changes that I have made recently). The program crashes in more than
one function. The IDE crashes with it (i.e., I can't use VBs great
debugging abilities). Error handlers do not keep the entire IDE from crashing.
I tried writing the current function to a log file
to find where the program crashes. Outputting to file at each function
slows the program down greatly (especially given it takes hours
to days for the program to crash). Is there another way?

I'm also going to try removing all redim statements for large
arrays from my program and set aside sufficient memory for them
at the beginning and see what happens.

Thanks Bill,

Brian
>
>"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>news:394f8ac7$1@news.devx.com...
>>
>> Hi Bill,
>>
>> shouldn't that give me an error message of "subscript out of range"
>> or something? Also, it usually works for many hours before
>> crashing on me.
>>
>>
>> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
>> >Hi Brian,
>> >
>> >I would suspect that one of the dynamic arrays inside the UDT is not
>> >dimensioned.
>> >
>> >
>> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>> >news:394f7606$1@news.devx.com...
>> >>
>> >> Hi,
>> >>
>> >> I wrote a while back asking about an appication error.
>> >> the error was something like:
>> >> the instruction at 0x... references memory at
>> >> 0x... the instruction could not be 'written'.
>> >>
>> >> I get this error sometimes, other times the system freezes,
>> >> and other times it works fine. I still don't know why.
>> >>
>> >> VB handles memory management and I am not using API calls, so
>> >theoretically
>> >>
>> >> everything should work (I don't really know much about how VB
>> >> handles memory).
>> >>
>> >> Is it possible that the problem is that I have very large arrays
>> >> that periodically need to be redimensioned. Some of my arrays
>> >> are in user defined types, others are in classes and std_modules.
>> >> Array sizes can be greater than 100,000. Some can be nested within
>> >> other arrays or arrays of UDTs.
>> >>
>> >> Redimensioning can cause arrays to be copied and written elsewhere
>> >> (true?). If I have complicated data structures, is it possible
>> >> that some error occurs such that VBs pointers no longer point
>> >> to the correct position in memory? Does VB have a garbage collector?
>> >> If not, is it possible that given the size of my arrays, the
>> >> system freezes after a number of hours running and fragmenting
>> >> heap memory?
>> >>
>> >> Thanks,
>> >>
>> >> Brian
>> >
>> >
>>
>
>

Re: VB Arrays and memory allocation

Okay, now shouldn't you be asking how did I guess you had a DoEvents
statement in your code <bg> !

Seriously , there are some major design issues you probably need to address.
First is why did you need to keep such large arrays in memory.
Next, you need to look very hard at your useage of DoEvents. Have you
included proper handling of procedure re-entry or any procedure running that
references any variable that the suspended procedure references.
As for the issue of redimming in another function while within a loop well
that goes double once you have DoEvents.
I'm pretty sure that the error you are getting is because your code is
referencing a variable that has gone out of scope.

What I would suggest is an error handler for each Sub/Function and write to
log in the error handlers. And definetly look at stopping other code running
when you have one procedure paused because of DoEvents.

"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
news:394f9848$1@news.devx.com...
>
> Hi Bill,
>
> >It should, but I wouldn't rely on it.. Do you have DoEvents in your code
> or
> >is it possible that your code can be reading from an array in a loop and
> yet
> >Redim it ?
>
> Yes, I have DoEvents in my code. What is the potential consequences of
that?
> I'll check to see whether I am reading from an array in a loop and
ReDiming
> it.
> I seem to remember having a problem with my arrays being
> temporarily locked in the compiled version (not in the IDE).
> The only way I could fix that was to not redim the problem
> array at all during the program (and consequently setting aside
> a more than necessary memory).
>
> when you say reading from an array in a loop and rediming it do you mean
>
> for x=1 to 10
> func y(x)
> redim preserve y(n)
> next x
>
> where func is a function
> or something like that? or where y is redimed in func?
>
> >
> >Also do you actually know the line of code that causes the failure, such
> as
> >will it fail when run from IDE ? (or put in line numbers and use the Erl
> >function to get the line number.. you will need error handlers for
virtually
> >every function/sub.)
> >
>
> I don't know the exact line of code, but I know some of the functions it
> occurs
> in (not the nested functions though). I thought it didn't fail in
> the IDE before, but I have found that it does (at least with
> the changes that I have made recently). The program crashes in more than
> one function. The IDE crashes with it (i.e., I can't use VBs great
> debugging abilities). Error handlers do not keep the entire IDE from
crashing.
> I tried writing the current function to a log file
> to find where the program crashes. Outputting to file at each function
> slows the program down greatly (especially given it takes hours
> to days for the program to crash). Is there another way?
>
> I'm also going to try removing all redim statements for large
> arrays from my program and set aside sufficient memory for them
> at the beginning and see what happens.
>
> Thanks Bill,
>
> Brian
>
> >
> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
> >news:394f8ac7$1@news.devx.com...
> >>
> >> Hi Bill,
> >>
> >> shouldn't that give me an error message of "subscript out of range"
> >> or something? Also, it usually works for many hours before
> >> crashing on me.
> >>
> >>
> >> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
> >> >Hi Brian,
> >> >
> >> >I would suspect that one of the dynamic arrays inside the UDT is not
> >> >dimensioned.
> >> >
> >> >
> >> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
> >> >news:394f7606$1@news.devx.com...
> >> >>
> >> >> Hi,
> >> >>
> >> >> I wrote a while back asking about an appication error.
> >> >> the error was something like:
> >> >> the instruction at 0x... references memory at
> >> >> 0x... the instruction could not be 'written'.
> >> >>
> >> >> I get this error sometimes, other times the system freezes,
> >> >> and other times it works fine. I still don't know why.
> >> >>
> >> >> VB handles memory management and I am not using API calls, so
> >> >theoretically
> >> >>
> >> >> everything should work (I don't really know much about how VB
> >> >> handles memory).
> >> >>
> >> >> Is it possible that the problem is that I have very large arrays
> >> >> that periodically need to be redimensioned. Some of my arrays
> >> >> are in user defined types, others are in classes and std_modules.
> >> >> Array sizes can be greater than 100,000. Some can be nested within
> >> >> other arrays or arrays of UDTs.
> >> >>
> >> >> Redimensioning can cause arrays to be copied and written elsewhere
> >> >> (true?). If I have complicated data structures, is it possible
> >> >> that some error occurs such that VBs pointers no longer point
> >> >> to the correct position in memory? Does VB have a garbage collector?
> >> >> If not, is it possible that given the size of my arrays, the
> >> >> system freezes after a number of hours running and fragmenting
> >> >> heap memory?
> >> >>
> >> >> Thanks,
> >> >>
> >> >> Brian
> >> >
> >> >
> >>
> >
> >
>

Re: VB Arrays and memory allocation

Okay, now shouldn't you be asking how did I guess you had a DoEvents
statement in your code <bg> !

Seriously , there are some major design issues you probably need to address.
First is why did you need to keep such large arrays in memory.
Next, you need to look very hard at your useage of DoEvents. Have you
included proper handling of procedure re-entry or any procedure running that
references any variable that the suspended procedure references.
As for the issue of redimming in another function while within a loop well
that goes double once you have DoEvents.
I'm pretty sure that the error you are getting is because your code is
referencing a variable that has gone out of scope.

What I would suggest is an error handler for each Sub/Function and write to
log in the error handlers. And definetly look at stopping other code running
when you have one procedure paused because of DoEvents.

"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
news:394f9848$1@news.devx.com...
>
> Hi Bill,
>
> >It should, but I wouldn't rely on it.. Do you have DoEvents in your code
> or
> >is it possible that your code can be reading from an array in a loop and
> yet
> >Redim it ?
>
> Yes, I have DoEvents in my code. What is the potential consequences of
that?
> I'll check to see whether I am reading from an array in a loop and
ReDiming
> it.
> I seem to remember having a problem with my arrays being
> temporarily locked in the compiled version (not in the IDE).
> The only way I could fix that was to not redim the problem
> array at all during the program (and consequently setting aside
> a more than necessary memory).
>
> when you say reading from an array in a loop and rediming it do you mean
>
> for x=1 to 10
> func y(x)
> redim preserve y(n)
> next x
>
> where func is a function
> or something like that? or where y is redimed in func?
>
> >
> >Also do you actually know the line of code that causes the failure, such
> as
> >will it fail when run from IDE ? (or put in line numbers and use the Erl
> >function to get the line number.. you will need error handlers for
virtually
> >every function/sub.)
> >
>
> I don't know the exact line of code, but I know some of the functions it
> occurs
> in (not the nested functions though). I thought it didn't fail in
> the IDE before, but I have found that it does (at least with
> the changes that I have made recently). The program crashes in more than
> one function. The IDE crashes with it (i.e., I can't use VBs great
> debugging abilities). Error handlers do not keep the entire IDE from
crashing.
> I tried writing the current function to a log file
> to find where the program crashes. Outputting to file at each function
> slows the program down greatly (especially given it takes hours
> to days for the program to crash). Is there another way?
>
> I'm also going to try removing all redim statements for large
> arrays from my program and set aside sufficient memory for them
> at the beginning and see what happens.
>
> Thanks Bill,
>
> Brian
>
> >
> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
> >news:394f8ac7$1@news.devx.com...
> >>
> >> Hi Bill,
> >>
> >> shouldn't that give me an error message of "subscript out of range"
> >> or something? Also, it usually works for many hours before
> >> crashing on me.
> >>
> >>
> >> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
> >> >Hi Brian,
> >> >
> >> >I would suspect that one of the dynamic arrays inside the UDT is not
> >> >dimensioned.
> >> >
> >> >
> >> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
> >> >news:394f7606$1@news.devx.com...
> >> >>
> >> >> Hi,
> >> >>
> >> >> I wrote a while back asking about an appication error.
> >> >> the error was something like:
> >> >> the instruction at 0x... references memory at
> >> >> 0x... the instruction could not be 'written'.
> >> >>
> >> >> I get this error sometimes, other times the system freezes,
> >> >> and other times it works fine. I still don't know why.
> >> >>
> >> >> VB handles memory management and I am not using API calls, so
> >> >theoretically
> >> >>
> >> >> everything should work (I don't really know much about how VB
> >> >> handles memory).
> >> >>
> >> >> Is it possible that the problem is that I have very large arrays
> >> >> that periodically need to be redimensioned. Some of my arrays
> >> >> are in user defined types, others are in classes and std_modules.
> >> >> Array sizes can be greater than 100,000. Some can be nested within
> >> >> other arrays or arrays of UDTs.
> >> >>
> >> >> Redimensioning can cause arrays to be copied and written elsewhere
> >> >> (true?). If I have complicated data structures, is it possible
> >> >> that some error occurs such that VBs pointers no longer point
> >> >> to the correct position in memory? Does VB have a garbage collector?
> >> >> If not, is it possible that given the size of my arrays, the
> >> >> system freezes after a number of hours running and fragmenting
> >> >> heap memory?
> >> >>
> >> >> Thanks,
> >> >>
> >> >> Brian
> >> >
> >> >
> >>
> >
> >
>

Re: VB Arrays and memory allocation

Hi Bill,

I'm always interested in finding out how to do things better. The reason
I have such large arrays in memory
is that I am running a simulation and I have a lot of individuals within
that simulation. Each individual
has characteristics that I need to keep track of. Further, the individuals
exist within a spatial grid. These
spatial elements interact with one another and therefore I must keep track
of spatial aspects too.
Other large arrays are kept to manage lists of individuals with certain characteristics,
so that I can
have immediate access to specific groups of individuals without having to
iterate through all individuals.
I originally used objects and collections to represent groups and individuals
but this turned out to be
too slow. I have built another class to handle indexing, and it does so via
several arrays. Errors in
indexing usually cause an out of range error, but I'll add in error handlers
to give more informative
output since, as you say, I shouldn't depend upon the expected error message.

>Seriously , there are some major design issues you probably need to address.
>First is why did you need to keep such large arrays in memory.

In terms of DoEvents, I am only running in a single thread (to my knowledge).
When DoEvents suspends the program, there are no other procedures running
(or I think there
should not be). Further, the program usually crashes after many hours when
I'm not at the computer
and not pausing the program.
>Next, you need to look very hard at your useage of DoEvents. Have you
>included proper handling of procedure re-entry or any procedure running
that
>references any variable that the suspended procedure references.
>As for the issue of redimming in another function while within a loop well
>that goes double once you have DoEvents.

But how does my code reference a variable that has gone out of scope? I can
easily see this happening
when I program in C++, but I thought it couldn't happen in VB (I am not using
any API calls).

>I'm pretty sure that the error you are getting is because your code is
>referencing a variable that has gone out of scope.
>
>What I would suggest is an error handler for each Sub/Function and write
to
>log in the error handlers. And definetly look at stopping other code running
>when you have one procedure paused because of DoEvents.

I'll give that a try.

Cheers,

Brian

>
>
>"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>news:394f9848$1@news.devx.com...
>>
>> Hi Bill,
>>
>> >It should, but I wouldn't rely on it.. Do you have DoEvents in your code
>> or
>> >is it possible that your code can be reading from an array in a loop
and
>> yet
>> >Redim it ?
>>
>> Yes, I have DoEvents in my code. What is the potential consequences of
>that?
>> I'll check to see whether I am reading from an array in a loop and
>ReDiming
>> it.
>> I seem to remember having a problem with my arrays being
>> temporarily locked in the compiled version (not in the IDE).
>> The only way I could fix that was to not redim the problem
>> array at all during the program (and consequently setting aside
>> a more than necessary memory).
>>
>> when you say reading from an array in a loop and rediming it do you mean
>>
>> for x=1 to 10
>> func y(x)
>> redim preserve y(n)
>> next x
>>
>> where func is a function
>> or something like that? or where y is redimed in func?
>>
>> >
>> >Also do you actually know the line of code that causes the failure, such
>> as
>> >will it fail when run from IDE ? (or put in line numbers and use the
Erl
>> >function to get the line number.. you will need error handlers for
>virtually
>> >every function/sub.)
>> >
>>
>> I don't know the exact line of code, but I know some of the functions
it
>> occurs
>> in (not the nested functions though). I thought it didn't fail in
>> the IDE before, but I have found that it does (at least with
>> the changes that I have made recently). The program crashes in more than
>> one function. The IDE crashes with it (i.e., I can't use VBs great
>> debugging abilities). Error handlers do not keep the entire IDE from
>crashing.
>> I tried writing the current function to a log file
>> to find where the program crashes. Outputting to file at each function
>> slows the program down greatly (especially given it takes hours
>> to days for the program to crash). Is there another way?
>>
>> I'm also going to try removing all redim statements for large
>> arrays from my program and set aside sufficient memory for them
>> at the beginning and see what happens.
>>
>> Thanks Bill,
>>
>> Brian
>>
>> >
>> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>> >news:394f8ac7$1@news.devx.com...
>> >>
>> >> Hi Bill,
>> >>
>> >> shouldn't that give me an error message of "subscript out of range"
>> >> or something? Also, it usually works for many hours before
>> >> crashing on me.
>> >>
>> >>
>> >> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
>> >> >Hi Brian,
>> >> >
>> >> >I would suspect that one of the dynamic arrays inside the UDT is not
>> >> >dimensioned.
>> >> >
>> >> >
>> >> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>> >> >news:394f7606$1@news.devx.com...
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> I wrote a while back asking about an appication error.
>> >> >> the error was something like:
>> >> >> the instruction at 0x... references memory at
>> >> >> 0x... the instruction could not be 'written'.
>> >> >>
>> >> >> I get this error sometimes, other times the system freezes,
>> >> >> and other times it works fine. I still don't know why.
>> >> >>
>> >> >> VB handles memory management and I am not using API calls, so
>> >> >theoretically
>> >> >>
>> >> >> everything should work (I don't really know much about how VB
>> >> >> handles memory).
>> >> >>
>> >> >> Is it possible that the problem is that I have very large arrays
>> >> >> that periodically need to be redimensioned. Some of my arrays
>> >> >> are in user defined types, others are in classes and std_modules.
>> >> >> Array sizes can be greater than 100,000. Some can be nested within
>> >> >> other arrays or arrays of UDTs.
>> >> >>
>> >> >> Redimensioning can cause arrays to be copied and written elsewhere
>> >> >> (true?). If I have complicated data structures, is it possible
>> >> >> that some error occurs such that VBs pointers no longer point
>> >> >> to the correct position in memory? Does VB have a garbage collector?
>> >> >> If not, is it possible that given the size of my arrays, the
>> >> >> system freezes after a number of hours running and fragmenting
>> >> >> heap memory?
>> >> >>
>> >> >> Thanks,
>> >> >>
>> >> >> Brian
>> >> >
>> >> >
>> >>
>> >
>> >
>>
>
>

Re: VB Arrays and memory allocation

Hi Bill,

I'm always interested in finding out how to do things better. The reason
I have such large arrays in memory
is that I am running a simulation and I have a lot of individuals within
that simulation. Each individual
has characteristics that I need to keep track of. Further, the individuals
exist within a spatial grid. These
spatial elements interact with one another and therefore I must keep track
of spatial aspects too.
Other large arrays are kept to manage lists of individuals with certain characteristics,
so that I can
have immediate access to specific groups of individuals without having to
iterate through all individuals.
I originally used objects and collections to represent groups and individuals
but this turned out to be
too slow. I have built another class to handle indexing, and it does so via
several arrays. Errors in
indexing usually cause an out of range error, but I'll add in error handlers
to give more informative
output since, as you say, I shouldn't depend upon the expected error message.

>Seriously , there are some major design issues you probably need to address.
>First is why did you need to keep such large arrays in memory.

In terms of DoEvents, I am only running in a single thread (to my knowledge).
When DoEvents suspends the program, there are no other procedures running
(or I think there
should not be). Further, the program usually crashes after many hours when
I'm not at the computer
and not pausing the program.
>Next, you need to look very hard at your useage of DoEvents. Have you
>included proper handling of procedure re-entry or any procedure running
that
>references any variable that the suspended procedure references.
>As for the issue of redimming in another function while within a loop well
>that goes double once you have DoEvents.

But how does my code reference a variable that has gone out of scope? I can
easily see this happening
when I program in C++, but I thought it couldn't happen in VB (I am not using
any API calls).

>I'm pretty sure that the error you are getting is because your code is
>referencing a variable that has gone out of scope.
>
>What I would suggest is an error handler for each Sub/Function and write
to
>log in the error handlers. And definetly look at stopping other code running
>when you have one procedure paused because of DoEvents.

I'll give that a try.

Cheers,

Brian

>
>
>"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>news:394f9848$1@news.devx.com...
>>
>> Hi Bill,
>>
>> >It should, but I wouldn't rely on it.. Do you have DoEvents in your code
>> or
>> >is it possible that your code can be reading from an array in a loop
and
>> yet
>> >Redim it ?
>>
>> Yes, I have DoEvents in my code. What is the potential consequences of
>that?
>> I'll check to see whether I am reading from an array in a loop and
>ReDiming
>> it.
>> I seem to remember having a problem with my arrays being
>> temporarily locked in the compiled version (not in the IDE).
>> The only way I could fix that was to not redim the problem
>> array at all during the program (and consequently setting aside
>> a more than necessary memory).
>>
>> when you say reading from an array in a loop and rediming it do you mean
>>
>> for x=1 to 10
>> func y(x)
>> redim preserve y(n)
>> next x
>>
>> where func is a function
>> or something like that? or where y is redimed in func?
>>
>> >
>> >Also do you actually know the line of code that causes the failure, such
>> as
>> >will it fail when run from IDE ? (or put in line numbers and use the
Erl
>> >function to get the line number.. you will need error handlers for
>virtually
>> >every function/sub.)
>> >
>>
>> I don't know the exact line of code, but I know some of the functions
it
>> occurs
>> in (not the nested functions though). I thought it didn't fail in
>> the IDE before, but I have found that it does (at least with
>> the changes that I have made recently). The program crashes in more than
>> one function. The IDE crashes with it (i.e., I can't use VBs great
>> debugging abilities). Error handlers do not keep the entire IDE from
>crashing.
>> I tried writing the current function to a log file
>> to find where the program crashes. Outputting to file at each function
>> slows the program down greatly (especially given it takes hours
>> to days for the program to crash). Is there another way?
>>
>> I'm also going to try removing all redim statements for large
>> arrays from my program and set aside sufficient memory for them
>> at the beginning and see what happens.
>>
>> Thanks Bill,
>>
>> Brian
>>
>> >
>> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>> >news:394f8ac7$1@news.devx.com...
>> >>
>> >> Hi Bill,
>> >>
>> >> shouldn't that give me an error message of "subscript out of range"
>> >> or something? Also, it usually works for many hours before
>> >> crashing on me.
>> >>
>> >>
>> >> "Bill McCarthy" <Bill_McC@iprimus.com.au> wrote:
>> >> >Hi Brian,
>> >> >
>> >> >I would suspect that one of the dynamic arrays inside the UDT is not
>> >> >dimensioned.
>> >> >
>> >> >
>> >> >"Brian Leung" <bleung@zoo.cam.ac.uk> wrote in message
>> >> >news:394f7606$1@news.devx.com...
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> I wrote a while back asking about an appication error.
>> >> >> the error was something like:
>> >> >> the instruction at 0x... references memory at
>> >> >> 0x... the instruction could not be 'written'.
>> >> >>
>> >> >> I get this error sometimes, other times the system freezes,
>> >> >> and other times it works fine. I still don't know why.
>> >> >>
>> >> >> VB handles memory management and I am not using API calls, so
>> >> >theoretically
>> >> >>
>> >> >> everything should work (I don't really know much about how VB
>> >> >> handles memory).
>> >> >>
>> >> >> Is it possible that the problem is that I have very large arrays
>> >> >> that periodically need to be redimensioned. Some of my arrays
>> >> >> are in user defined types, others are in classes and std_modules.
>> >> >> Array sizes can be greater than 100,000. Some can be nested within
>> >> >> other arrays or arrays of UDTs.
>> >> >>
>> >> >> Redimensioning can cause arrays to be copied and written elsewhere
>> >> >> (true?). If I have complicated data structures, is it possible
>> >> >> that some error occurs such that VBs pointers no longer point
>> >> >> to the correct position in memory? Does VB have a garbage collector?
>> >> >> If not, is it possible that given the size of my arrays, the
>> >> >> system freezes after a number of hours running and fragmenting
>> >> >> heap memory?
>> >> >>
>> >> >> Thanks,
>> >> >>
>> >> >> Brian
>> >> >
>> >> >
>> >>
>> >
>> >
>>
>
>