[Haskell-cafe] heap lifetime question

Galchin, Vasili vigalchin at gmail.com
Thu Aug 7 02:33:07 EDT 2008


ok .. I will take a stab at it ... /ghc-6.8.2/libraries/base/Foreign/Marshal
.... I am not so familiar with the ghc run-time model ...

V.

On Thu, Aug 7, 2008 at 1:26 AM, Galchin, Vasili <vigalchin at gmail.com> wrote:

> In which directory are they?
>
> Vasili
>
>
> On Thu, Aug 7, 2008 at 12:58 AM, Bulat Ziganshin <
> bulat.ziganshin at gmail.com> wrote:
>
>> Hello Vasili,
>>
>> Thursday, August 7, 2008, 9:33:32 AM, you wrote:
>>
>> oh, it was my mistake. alloca behavior is completely defined by it's
>> generic implementation:
>>
>> allocaBytes      :: Int -> (Ptr a -> IO b) -> IO b
>> allocaBytes size  = bracket (mallocBytes size) free
>>
>> although GHC implementation is much more efficient
>>
>> btw, why you can't download ghc library sources and read them yourself??
>>
>>
>>
>> > If I am correct, I cannot associate a ForeignPtr with alloca or
>> > allocaBytes object via "newForeignPtr" because the
>> > alloca/allocaBytes heap object will be GC'd when I leave the
>> > function that allocated this object/. I.e. if I have a heap object
>> > that I want to live beyond a function invocation, I must be very careful
>> in coding....
>> >
>> > Vasili
>>
>> > On Thu, Aug 7, 2008 at 12:30 AM, Galchin, Vasili <vigalchin at gmail.com>
>> wrote:
>> >
>> > so Bulat ..
>>
>> >      You seem to be saying what I suspect ... i.e. if an
>> > allocaBytes call is inside a function, when the function is exited
>> > then the said heap object is GC'd??
>>
>> > Regards, Vasili
>> >
>>
>> >
>>
>> > On Thu, Aug 7, 2008 at 12:25 AM, Bulat Ziganshin
>> > <bulat.ziganshin at gmail.com> wrote:
>> >  Hello Vasili,
>> >
>>
>> >  Thursday, August 7, 2008, 9:13:43 AM, you wrote:
>> >
>>  >>     What is the lifetime of various heap objects ... e.g. created by
>> allocaBytes, alloca, etc?
>> >
>> >
>> > alloca/allocaBytes just mimicks stack allocation but actually allocates
>> >  buffer in usual heap. this buffer lives while references to it exists
>> >
>> >  on practice, it's usually gc'ed by next minor GC
>> >
>> >  --
>> >  Best regards,
>> >   Bulat                            mailto:Bulat.Ziganshin at gmail.com
>> >
>> >
>>
>> >
>>
>> >
>>
>>
>> --
>> Best regards,
>>  Bulat                            mailto:Bulat.Ziganshin at gmail.com
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080807/f970089a/attachment.htm


More information about the Haskell-Cafe mailing list