Losing memory because of String usage

General FreeBASIC programming questions.
fxm
Posts: 9183
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Losing memory because of String usage

Postby fxm » Jun 01, 2018 13:57

@MrSwiss,
Your overload "Destructor xyz2 ()" is useless because the implicit destructor of xyz2 already does an equivalent thing (the member string already being a pre-defined object itself).
Last edited by fxm on Jun 01, 2018 15:06, edited 2 times in total.
dodicat
Posts: 5943
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Losing memory because of String usage

Postby dodicat » Jun 01, 2018 14:03

Mr Swiss
I understand of course.
But I believe wallyg has thousands of code lines (using any ptr --Correct wallyg??)
And 57 types.
So, I take my lead from there.
Hopefully he/she can implement your other solutions easily.
MrSwiss
Posts: 3264
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Losing memory because of String usage

Postby MrSwiss » Jun 01, 2018 14:19

@fxm, all the implicit 'stuff' unfortunately hasn't the decency, to tell us:
"what it does" (or not), in any possible constellation ...

@dodicat, your reasoning has substance (but, it may also be, a simple
oversight, by OP).
fxm
Posts: 9183
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Losing memory because of String usage

Postby fxm » Jun 01, 2018 14:34

Everything that is predefined becomes implicit for the user.
But it would not occur to you to destroy the string data just before the variable comes out of its scope, like that:

Code: Select all

Scope
  Dim As String s
  s = String(1000, 0)
  '.....
  s = ""  '' useless
End Scope

So, why do it for a member string?
MrSwiss
Posts: 3264
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Losing memory because of String usage

Postby MrSwiss » Jun 01, 2018 14:52

fxm wrote:So, why do it for a member string?
For examples sake ... to show, what implicit is expected to do.
fxm
Posts: 9183
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Losing memory because of String usage

Postby fxm » Jun 01, 2018 15:37

If user defines its own constructor (or destructor), all is done in the implicit default construction (or destruction) is added before (or after) its code body.
But the things done in the default copy-construction (or default copy-assignation) are never added to the user copy-constructor (or copy-assignment operator).
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Losing memory because of String usage

Postby sancho3 » Jun 02, 2018 1:08

wallyg wrote:Thank you all for trying to help. ...I asked a simple question...I expected to get a 2 character response ie. NO. or a 1 line example on how to do this...,

This is an open forum and the answers here are not just for you but for the next guy as well.
Perhaps the next guy will want to learn from the answers.
but my programs work and get the job done

Well they mostly work right? ;)

Return to “General”

Who is online

Users browsing this forum: No registered users and 37 guests