You are only overwriting the pointer to the string (a string is essentially a
pointer and a length). If you want to use memory and then zero it out, use a
byte slice instead and be careful to not call append where append might
allocate new memory. Take a look at https://play.golang.org/p/GkrKRSvkoRJ.
-Paul
On Aug 28, 2018, at 11:45 AM, Jay Sharma
<[email protected]<mailto:[email protected]>> wrote:
@Jan, The example you shown it is copying a string to new variable. but my
question was related to same variable.
I want to know if I have variable :
x := "testsring"
Now it overwrite the content of same variable x to some other value:
x = "new1string"
Will it overwrite the same memory or it will create some copy ?
@Jake Montgomery,
It is about security. I have some keys and I want to delete the content of
key, when no longer required. Here my API is expecting a string key.
On Tuesday, August 28, 2018 at 8:25:27 PM UTC+5:30, Jay Sharma wrote:
Hi All,
I went through documentation and many post. Every where it is specified strings
are immutable.
I have some string :
x := "teststring"
I want to wipe out/overwrite the content of this string x from disk/memory.
As per me the simplest way to do this:
x = ""
or If I want to overwrite it with some new content, I can do this: [Here length
of new string is equal to length of old string]
x = "new1string"
As I am overwriting the content with new content, Is it inplace replacement
[same memory is being updated] or a new copy will be created with new content
and old content will be there in the memory ?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
[email protected]<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.