Sign in to follow this  
Followers 0
GyuK

function is declaring new variables?

4 posts in this topic

#1 ·  Posted (edited)

i have an function thats gets looped quite some times in my script, it this function: 

func _iniReadSection($ininame,$inisec)
   dim $array[1][3]
   $j = 1
   $inih = fileopen($ininame,0)
   $inifile = FileReadToArray($inih)
   if ubound($inifile) < 10 Then
       return 0
   EndIf
   $inifile[0] = (ubound($inifile) - 1)
   for $i = 1 to $inifile[0]
       if $inifile[$i] = "[" & $inisec & "]" Then
           $start = $i + 1
       EndIf
   Next
   for $i = $start to $inifile[0]
   if not StringInStr($inifile[$i],"]") Then
       redim $array[$j + 1][3]
       $array[$j][1] = stringmid($inifile[$i],1,(stringinstr($inifile[$i],"=")-1))
       $array[$j][2] = stringmid($inifile[$i],(stringinstr($inifile[$i],"=")+1))
       $j += 1
   Else
       $array[0][0] = ubound($array) - 1
       return $array
   EndIf
   Next
   $array[0][0] = ubound($array) - 1
   return $array
EndFunc

if you try to do something like:

while 1
    $teste = _IniReadSection("config.ini","GERAL")
WEnd

the script will start getting so many memory till it gets to 4gb of ram and get a error, "Error allocating memory", there is something wrong with the function?, aren't the variables inside function supposed to be released once it reach the "return" line?

Edited by GyuK

Share this post


Link to post
Share on other sites



GyuK,

You open a file each time you enter the function [fileopen($ininame,0)] but you never close it - Windows will run out of handles pretty quickly, which is probably the cause of your problem. ;)

Also, why are you not using the built-in IniReadSection function? It looks as if the array returned from your function is essentially similar. :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

GyuK,

You open a file each time you enter the function [fileopen($ininame,0)] but you never close it - Windows will run out of handles pretty quickly, which is probably the cause of your problem. ;)

Also, why are you not using the built-in IniReadSection function? It looks as if the array returned from your function is essentially similar. :huh:

M23

 

yup, that was the problem(im so dumb), fixed it thanks

"Only the first 32767 chars are read for legacy reasons." cause of that

Share this post


Link to post
Share on other sites

GuyK,

Glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0