On Sat, 12 Feb 2011, Artyom Shalkhakov wrote:
>>2011/2/12, Guillaume Brunerie <guillaume.brunerie@...>:
>>> 2011/2/9 Hongwei Xi <hwxi@...>
>>>
>>>> On Wed, 9 Feb 2011, Guillaume Brunerie wrote:
>>>>
>>>> >>But you could use string_of_strbuf or string_of_strptr, why do you need
>>>> to
>>>> >>cast with such unsafe functions?
>>>>
>>>> string_of_strptr turns a strptr into a string, which can only be reclaimed
>>>> by the GC. If no GC is running, then it is a memory leak.
>>>
>>>
>>> So there is no clean solution?
>>> It seems that the problem comes from the fact that a constant string is
>>> given the type 'string' even if it will not be freed by the GC (because it's
>>> a constant string in the data segment), and that constant strings are used
>>> even in a program without GC.
>>
>>This is a bit confusing. When I needed a mutable string, I've allocated a buffer
>>on stack, then created a string buffer from it, worked on that (or casted
>>it to a strptr IIRC), and when I was done, I casted the string buffer back
>>to the buffer so as to show the typechecker there was no memory leak.
>>I think that is correct, isn't it?
That is how I typically do it, too.
This kind of casting and casting back is certainly boring and it would
be really nice if there is a way that this can be done automatically
(something like tactics in theorem-proving).
However, I am not advocating that tactics be supported in ATS directly.
That would likely lead to a mess. Instead, such support can be made
available in some kind of IDE for ATS. It is a new kind of IDE; it is
a kind that goes beyond coloring, highlighting and auto-completion.
--Hongwei
Computer Science Department
Boston University
111 Cummington Street
Boston, MA 02215
Email: hwxi@...
Url: http://www.cs.bu.edu/~hwxi
Tel: +1 617 358 2511 (office)
Fax: +1 617 353 6457 (department)
|