It is currently Tue Oct 20, 2020 3:50 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Sat Aug 17, 2019 8:10 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
Link to bug-reports
viewtopic.php?f=4&t=71568&start=0#p531589
viewtopic.php?f=4&t=71568&start=15#p538347

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Sat Aug 17, 2019 8:44 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 731
skywalk wrote:
Yes, so I am asking why Mijikai says PB strings are broken?


Are you trolling?


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Sat Aug 17, 2019 9:06 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
Mijikai wrote:
skywalk wrote:
Yes, so I am asking why Mijikai says PB strings are broken?


Are you trolling?

No, he hadn't been involved with it before.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Sat Aug 17, 2019 9:11 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3336
Location: Boston, MA
@Mijikai, Surely not. I thought you were because you trash the entire v571 for a small bug? It does not cause leaks, only inefficient with memory. I cannot wait for the release with no bugs!

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Sat Aug 17, 2019 9:18 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
Not quite...
What didn't cause any problems with PB v5.6x, leads to a memory leak with PB v5.7x.
Code:
Structure sFoo
  iVal.i
  sVal.s
EndStructure

*mem.sFoo = AllocateMemory(SizeOf(sFoo))
*mem\sVal = "Hello"
;
; ...
;
*mem\sVal = #Null$
FreeMemory(*mem)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Sat Aug 17, 2019 9:54 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3336
Location: Boston, MA
haha, but we go in circles :shock:
mk-soft wrote:
If you do everything right, there will be no memory leakage
- AllocateStructure -> FreeStructure
- AllocateMemory -> ClearMemory -> FreeMemory.

You are clearing memory with a loosely documented step(#Null$). I only found it mentioned here in the manual with no examples.
manual wrote:
There are two special constants for strings:
#Empty$: represents an empty string (exactly the same as "")
#Null$ : represents an null string. This can be used for API
functions requiring a null pointer to a string, or to really free a string.

Curious? Why not stick with AllocateStructure->FreeStructure to avoid this issue?

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Sat Aug 17, 2019 11:06 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
skywalk wrote:
Curious? Why not stick with AllocateStructure->FreeStructure to avoid this issue?

Depends on the task if you need it that way.
It is not always possible to work with AllocateStructure or to rebuild the whole structure every time only to set a string to Nothing for API calls.

It should work as described in the description.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Wed Aug 28, 2019 12:03 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2681
Location: Germany
Josh Link: viewtopic.php?f=4&t=71568&start=15#p541135

Set String to Nothing :wink:
Code:
Macro Nothing
  "!_PB_NullConstant_!"
EndMacro

Define s.s

s = "Global Hello World"
Debug s
Debug "Adress to String = " + @s
s = #Null$
Debug "Adress to String (#Null$) = " + @s ; <- Must be 0.

s = Nothing
Debug "Adress to String (Nothing) = " + @s ; <- Must be 0.

Structure udtFoo
  iVal.i
  sVal.s
EndStructure

a.udtFoo
a\iVal = 100
a\sVal = "Structure Hello World"
Debug a\sVal
Debug "Adress to String = " + PeekI(@a+OffsetOf(udtFoo\sVal))
Debug a\sVal

a\sVal = Nothing
Debug "Adress to String (Nothing) = " + PeekI(@a+OffsetOf(udtFoo\sVal))
Debug a\sVal


ASM-Code is ok
Quote:
...
; s = Nothing
XOR rsi,rsi
LEA rdi,[v_s]
CALL _SYS_FastAllocateStringFree4
...
; a\sVal = Nothing
XOR rsi,rsi
LEA rdi,[rbp+8]
CALL _SYS_FastAllocateStringFree4
...

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Wed Aug 28, 2019 1:38 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 731
So basically just the constant is wrong?
Sounds like good news.


Top
 Profile  
Reply with quote  
 Post subject: Re: Workaround FreeString Resources (Set to Nothing)
PostPosted: Wed Aug 28, 2019 2:51 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3336
Location: Boston, MA
This is why I hate this approach.
Just make a function that clears strings and be done with this. :evil:
Code:
EnableExplicit
#Null$ = "!_PB_NullConstant_!"
Debug #Null$    ;BAD Design if constant has hidden meaning?

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 32 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye