Losing memory because of String usage

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

Re: Losing memory because of String usage

Post by fxm »

@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: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Losing memory because of String usage

Post by dodicat »

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: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Losing memory because of String usage

Post by MrSwiss »

@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
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Losing memory because of String usage

Post by fxm »

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: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Losing memory because of String usage

Post by MrSwiss »

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

Re: Losing memory because of String usage

Post by fxm »

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

Post by sancho3 »

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? ;)
Post Reply