String and gc

hello,
I actually converting my data structures to linear ones to do manual memory
management.
My question is how memory is handled for string variables ?
Is it similar to c++ (string memory is copied when passed by value as a
function argument)

Should I use strptr1 instead for programs not using GC ?

thanks a lot :wink:

thanks :wink:

For sure having linear type to follow memory usage is very convenient but
can be very tricky for highly shared resources

This is a very interesting topic. It depends what you are doing and what
your goal is.

For something relatively small, using ‘strptr1’ for strings is fine.

For something more complicated that requires sharing of strings, one may
want to use
ref-counted strings.

In ATS2, I added a type strobjref:

which is for reference-counted strings.

At the beginning of a project, I often do not know for sure what kind of
strings I want.
So I often introduce an abstract type

absviewtype mystring (l:addr)

First I implement mystring based on strptr. Later, I may change the
implementation,
making it based on strobjref or something else.

In practice, if string sharing is allowed. then memory leaks are often very
difficult to prevent.
For instance, there are many leaks in graphviz (according to bug reports).
ATS is very good
for stopping this kind of problems.

Usually, highly shared resources are handled by some form of reference
counting.

Over the past few years, the most complicated
resource handling I encountered is the handling kobjects in linux kernel.
Often I see that complications in resource handling are primarily
added due to lack of linear types. For instance, in GTK, something called
’float-reference’ was invented, which I had to get rid of when
doing an API for GTK in ATS.