Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Type Statements and Memory Release

I have read through the several posts on this subject, but am still
having problems understanding what the best way forward is.

I'm running on Excel 2000.

I have 3 different Type statements, for 3 different INI file types. I
occasionally have problems running out of string space. I also think
it's good practice to release memory as you go along, so I'd really
like to release the memory once I've read an INI file, using Get, and
transferred the contents to the objects I'm working with.

So, I've tried putting the Type statements into a class module so that
I can set it to Nothing when I'm finished but, of course, it's not
allowed to put Type statements into a class module. I can't simply
set the Type statement to = Nothing, since it's not an object.

Can anyone suggest how I can easily release this memory and claw back
some of the string space I run out of from time to time?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Type Statements and Memory Release

The typing in itself doesnt take the memory...


it's the array of data..
when the array goes out of scope or is erased
the memory will be freed

IF your array is defined as MODULE level
Erase it or set it to empty when you're done using it.

If the array is defined at PROCEDURE level,
the object goes out of scope when the procedure ends and tiu's resources
are freed automatically.
(You can still erase it or set it to empty.

A small demo...

Option Explicit

Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type

'KERNEL32
Private Declare Sub GlobalMemoryStatus Lib "kernel32" ( _
lpBuffer As MEMORYSTATUS)

Type structure
string1 As String
string2 As String
string3 As String
string4 As String
End Type

Sub MemUsageTest()
Dim aStruc() As structure
Dim i
dump
ReDim aStruc(10000)
dump
With aStruc(0)
.string1 = String(1024, "a")
.string2 = String(1024, "b")
.string3 = String(1024, "c")
.string4 = String(1024, "d")
End With

For i = 1 To UBound(aStruc)
With aStruc(0)
aStruc(i).string1 = .string1
aStruc(i).string2 = .string2
aStruc(i).string3 = .string3
aStruc(i).string4 = .string4
End With
Next

dump
Erase aStruc
dump

End Sub



Sub dump()
Static old As MEMORYSTATUS
Dim mem As MEMORYSTATUS
Dim bOld As Boolean
Dim txt As String

GlobalMemoryStatus mem
bOld = old.dwMemoryLoad 0

With mem
txt = txt & "% used: " & Format$( _
.dwMemoryLoad, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwMemoryLoad - old.dwMemoryLoad, _
"@@@@@@@@@@@"), "") & vbCrLf
txt = txt & "Physical memory free: " & Format$( _
.dwAvailPhys, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwAvailPhys - old.dwAvailPhys, "@@@@@@@@@@@"), _
"") & vbCrLf
txt = txt & "Free virtual memory: " & Format$( _
.dwAvailVirtual, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwAvailVirtual - old.dwAvailVirtual, _
"@@@@@@@@@@@"), "") & vbCrLf
txt = txt & "Free page file size: " & Format$( _
.dwAvailPageFile, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwAvailPageFile - old.dwAvailPageFile, _
"@@@@@@@@@@@"), "") & vbCrLf
End With

Debug.Print txt
old = mem

End Sub







keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Neil Miller) wrote :

I have read through the several posts on this subject, but am still
having problems understanding what the best way forward is.

I'm running on Excel 2000.

I have 3 different Type statements, for 3 different INI file types. I
occasionally have problems running out of string space. I also think
it's good practice to release memory as you go along, so I'd really
like to release the memory once I've read an INI file, using Get, and
transferred the contents to the objects I'm working with.

So, I've tried putting the Type statements into a class module so that
I can set it to Nothing when I'm finished but, of course, it's not
allowed to put Type statements into a class module. I can't simply
set the Type statement to = Nothing, since it's not an object.

Can anyone suggest how I can easily release this memory and claw back
some of the string space I run out of from time to time?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Type Statements and Memory Release

Thanks for your reply keepITcool

The problem is that the Type Statements are not as simple as an array,
e.g.

Public Type CMS_iNi_seRveR_boDy_tYpE
biLlaBlE_eXpenSe_aCtiviTy_tYpE_keYwoRd As String
CMS_dEbuG As Boolean
CMS_qUieT As Boolean
eMaiL_copY_To_aDminiStraToR As Boolean
eMaiL_neW_uSeR_msG As String
eMaiL_rEseT_uSeR_msG As String
eMaiL_suBjecT As String
eXpenSe_aCtiviTy_tYpE_keYwoRd As String
Fee_eArninG_aCtiviTy_tYpE_keYwoRd As String
LpEr As Integer
nExT_cAsE_nuMbeR As Integer
NoN_biLlaBlE_eXpenSe_aCtiviTy_tYpE_keYwoRd As String
sErveR_aCtiviTy_dEscRipTioNs_peR_tYpE(10, 25) As String
aCtiviTy_tYpE_keYs(CMS_maX_uSeR_aCtiviTy_tYpEs - 1) As String
sErveR_Fee_eArneRs(CMS_maX_uSeRs) As String
sErveR_paYmeNt_teRmS(CMS_maX_pAymEnT_tErMs - 1) As String
sErveR_rEgioNs(CMS_maX_rEgioNs - 1) As String
sErveR_sCopE(CMS_maX_rEgioNs - 1) As String
sErveR_uSeRs(CMS_maX_uSeR_aTtribUteS, CMS_maX_uSeRs) As Variant
End Type

These Type Statements are declared at module level and I was hoping
that there was an easier way that erasing each variable or array
within the type.

Thanks for your help.

Neil

keepITcool wrote in message . ..
The typing in itself doesnt take the memory...


it's the array of data..
when the array goes out of scope or is erased
the memory will be freed

IF your array is defined as MODULE level
Erase it or set it to empty when you're done using it.

If the array is defined at PROCEDURE level,
the object goes out of scope when the procedure ends and tiu's resources
are freed automatically.
(You can still erase it or set it to empty.

A small demo...

Option Explicit

Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type

'KERNEL32
Private Declare Sub GlobalMemoryStatus Lib "kernel32" ( _
lpBuffer As MEMORYSTATUS)

Type structure
string1 As String
string2 As String
string3 As String
string4 As String
End Type

Sub MemUsageTest()
Dim aStruc() As structure
Dim i
dump
ReDim aStruc(10000)
dump
With aStruc(0)
.string1 = String(1024, "a")
.string2 = String(1024, "b")
.string3 = String(1024, "c")
.string4 = String(1024, "d")
End With

For i = 1 To UBound(aStruc)
With aStruc(0)
aStruc(i).string1 = .string1
aStruc(i).string2 = .string2
aStruc(i).string3 = .string3
aStruc(i).string4 = .string4
End With
Next

dump
Erase aStruc
dump

End Sub



Sub dump()
Static old As MEMORYSTATUS
Dim mem As MEMORYSTATUS
Dim bOld As Boolean
Dim txt As String

GlobalMemoryStatus mem
bOld = old.dwMemoryLoad 0

With mem
txt = txt & "% used: " & Format$( _
.dwMemoryLoad, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwMemoryLoad - old.dwMemoryLoad, _
"@@@@@@@@@@@"), "") & vbCrLf
txt = txt & "Physical memory free: " & Format$( _
.dwAvailPhys, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwAvailPhys - old.dwAvailPhys, "@@@@@@@@@@@"), _
"") & vbCrLf
txt = txt & "Free virtual memory: " & Format$( _
.dwAvailVirtual, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwAvailVirtual - old.dwAvailVirtual, _
"@@@@@@@@@@@"), "") & vbCrLf
txt = txt & "Free page file size: " & Format$( _
.dwAvailPageFile, "@@@@@@@@@@@") & vbTab & IIf(bOld, _
Format$(mem.dwAvailPageFile - old.dwAvailPageFile, _
"@@@@@@@@@@@"), "") & vbCrLf
End With

Debug.Print txt
old = mem

End Sub







keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Neil Miller) wrote :

I have read through the several posts on this subject, but am still
having problems understanding what the best way forward is.

I'm running on Excel 2000.

I have 3 different Type statements, for 3 different INI file types. I
occasionally have problems running out of string space. I also think
it's good practice to release memory as you go along, so I'd really
like to release the memory once I've read an INI file, using Get, and
transferred the contents to the objects I'm working with.

So, I've tried putting the Type statements into a class module so that
I can set it to Nothing when I'm finished but, of course, it's not
allowed to put Type statements into a class module. I can't simply
set the Type statement to = Nothing, since it's not an object.

Can anyone suggest how I can easily release this memory and claw back
some of the string space I run out of from time to time?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Type Statements and Memory Release

Neil..

I'm not sure I'd have defined a usertype like that..
as it's a memory hog at the best of times..

BUT.. for all problems there must be a solution..

instead of declaring your variables as TYPE
declare m as an array of Type..

THEN redim the array.. et voila!

Dim aCMS() As CMS_iNi_seRveR_boDy_tYpE

Sub MemUsageTest()
dump
ReDim aCMS(0)
dump
Erase aCMS
dump
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Neil Miller) wrote :

Thanks for your reply keepITcool

The problem is that the Type Statements are not as simple as an array,
e.g.

Public Type CMS_iNi_seRveR_boDy_tYpE
biLlaBlE_eXpenSe_aCtiviTy_tYpE_keYwoRd As String
CMS_dEbuG As Boolean
CMS_qUieT As Boolean
eMaiL_copY_To_aDminiStraToR As Boolean
eMaiL_neW_uSeR_msG As String
eMaiL_rEseT_uSeR_msG As String
eMaiL_suBjecT As String
eXpenSe_aCtiviTy_tYpE_keYwoRd As String
Fee_eArninG_aCtiviTy_tYpE_keYwoRd As String
LpEr As Integer
nExT_cAsE_nuMbeR As Integer
NoN_biLlaBlE_eXpenSe_aCtiviTy_tYpE_keYwoRd As String
sErveR_aCtiviTy_dEscRipTioNs_peR_tYpE(10, 25) As String
aCtiviTy_tYpE_keYs(CMS_maX_uSeR_aCtiviTy_tYpEs - 1) As String
sErveR_Fee_eArneRs(CMS_maX_uSeRs) As String
sErveR_paYmeNt_teRmS(CMS_maX_pAymEnT_tErMs - 1) As String
sErveR_rEgioNs(CMS_maX_rEgioNs - 1) As String
sErveR_sCopE(CMS_maX_rEgioNs - 1) As String
sErveR_uSeRs(CMS_maX_uSeR_aTtribUteS, CMS_maX_uSeRs) As Variant
End Type

These Type Statements are declared at module level and I was hoping
that there was an easier way that erasing each variable or array
within the type.

Thanks for your help.

Neil


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Type Statements and Memory Release

Thanks again keepITcool - that works great. At the risk of
"overstaying my welcome", I would appreciate you expanding on your
comment that you would not have defined a usertype in the way I
described. As I mentioned earlier in the initial Post, the INI files
get read and written using Get/Put and, to some extent, I am limited
by the datatypes allowed with these types of file.

Your thoughts would be appreciated if you have the time.

Thanks again.........Neil

keepITcool wrote in message . ..
Neil..

I'm not sure I'd have defined a usertype like that..
as it's a memory hog at the best of times..

BUT.. for all problems there must be a solution..

instead of declaring your variables as TYPE
declare m as an array of Type..

THEN redim the array.. et voila!

Dim aCMS() As CMS_iNi_seRveR_boDy_tYpE

Sub MemUsageTest()
dump
ReDim aCMS(0)
dump
Erase aCMS
dump
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Neil Miller) wrote :

Thanks for your reply keepITcool

The problem is that the Type Statements are not as simple as an array,
e.g.

Public Type CMS_iNi_seRveR_boDy_tYpE
biLlaBlE_eXpenSe_aCtiviTy_tYpE_keYwoRd As String
CMS_dEbuG As Boolean
CMS_qUieT As Boolean
eMaiL_copY_To_aDminiStraToR As Boolean
eMaiL_neW_uSeR_msG As String
eMaiL_rEseT_uSeR_msG As String
eMaiL_suBjecT As String
eXpenSe_aCtiviTy_tYpE_keYwoRd As String
Fee_eArninG_aCtiviTy_tYpE_keYwoRd As String
LpEr As Integer
nExT_cAsE_nuMbeR As Integer
NoN_biLlaBlE_eXpenSe_aCtiviTy_tYpE_keYwoRd As String
sErveR_aCtiviTy_dEscRipTioNs_peR_tYpE(10, 25) As String
aCtiviTy_tYpE_keYs(CMS_maX_uSeR_aCtiviTy_tYpEs - 1) As String
sErveR_Fee_eArneRs(CMS_maX_uSeRs) As String
sErveR_paYmeNt_teRmS(CMS_maX_pAymEnT_tErMs - 1) As String
sErveR_rEgioNs(CMS_maX_rEgioNs - 1) As String
sErveR_sCopE(CMS_maX_rEgioNs - 1) As String
sErveR_uSeRs(CMS_maX_uSeR_aTtribUteS, CMS_maX_uSeRs) As Variant
End Type

These Type Statements are declared at module level and I was hoping
that there was an easier way that erasing each variable or array
within the type.

Thanks for your help.

Neil



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Type Statements and Memory Release


I'd focus on trying to move those fixed arrays out of the base structure.
certainly the ones the size with CMS_MAX_USERS.

I've no idea of the raw data.. But max users is set on a 'global' level.
I'd assume it was a 'per server' setting.

If you have 1 1000 user server.. and 100 10 user servers...
you'd need to allocate m all for max_users e.g. 1000

Set the user_size into the type, and make the arrays of variable length.
e.g.

Type MyType
rows As Integer
cols As Integer
prop() As String
End Type

Sub ff()
Dim aTypes(40) As MyType

With aTypes(0)
.rows = 10
.cols = 2
ReDim .prop(.rows, .cols)
.prop(0, 0) = 1
.prop(0, 1) = 2
'etc
End With
'etc etc

End Sub



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Neil Miller) wrote :

Thanks again keepITcool - that works great. At the risk of
"overstaying my welcome", I would appreciate you expanding on your
comment that you would not have defined a usertype in the way I
described. As I mentioned earlier in the initial Post, the INI files
get read and written using Get/Put and, to some extent, I am limited
by the datatypes allowed with these types of file.

Your thoughts would be appreciated if you have the time.

Thanks again.........Neil

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
XL 2007 - Out of Memory - memory leak/bug? PCLIVE Excel Discussion (Misc queries) 0 March 23rd 09 03:31 PM
Release Memory Jeff Excel Discussion (Misc queries) 1 September 25th 06 09:28 PM
Suggestions for the Next Release ExcelPro Excel Discussion (Misc queries) 0 May 24th 06 07:45 AM
Excel 12 New Release Bart Vwb Excel Discussion (Misc queries) 5 October 4th 05 10:07 PM
Release files from memory?? Ron[_21_] Excel Programming 3 March 5th 04 12:49 PM


All times are GMT +1. The time now is 01:16 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"