Fwd: Memory allocation for global ptr

१७ भ्यु
नपढिएको पहिलो सन्देशमा जानुहोस्

Ben Swift

नपढिएको,
२०१६ अप्रिल २१, ००:४७:०९१६/४/२१
प्रापक Extempore, Hack Spanner
Hi Dave

I'm forwarding the message to the mailing list, so that the burgeoning
Extempore community can weigh in as well.

Cheers,
Ben

Hack Spanner <hacks...@gmail.com> writes:

> Hi Ben,
>
> Hope this is the appropriate address to contact you about xt-lang
> questions...
>
> I am trying to allocate some memory through a pointer at the top-level so:
>
> (bind-val ptr i32* (zalloc))
>
> I get a bunch of strange messages when I try this.
> However, if I define an allocation function, thusly:
>
> (bind-func i32_alloc
> (lambda ()
> (let ((pnew:i32* (zalloc)))
> pnew)))
>
> (bind-val ptr i32* (i32_alloc))
>
> It works fine.
>
> Is this expected behavior? Am I doing something wrong the first way?
>
> -Dave

Toby Gifford

नपढिएको,
२०१६ अप्रिल २१, ००:५८:१०१६/४/२१
प्रापक extemp...@googlegroups.com
Hi Dave, the syntax for (bind-val) is a bit different to the way you are using it. The syntax (or perhaps semantics) depends on whether you are binding a pointer value or a normal value.

Normal:  (bind-val <variable-name> <variable-type> <value>)
Pointer:  (bind-val <variable-name> <variable-type>* <number-of-elements-to-allocate>)

So, your first line should be (bind-val ptr i32* 1) if you just want a single pointer.






--
You received this message because you are subscribed to the Google Groups "Extempore" group.
To unsubscribe from this group and stop receiving emails from it, send an email to extemporelan...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hackspanner

नपढिएको,
२०१६ अप्रिल २१, ०१:५८:१२१६/४/२१
प्रापक Extempore
Ah, I see. So then the ptr is allocated on the heap with halloc?

Ben Swift

नपढिएको,
२०१६ अप्रिल २१, ०२:१२:२२१६/४/२१
प्रापक extemp...@googlegroups.com
Yep, that's correct - top-level bind-vals are always on the heap.

I should also add that in both cases described by Toby the final
"argument" is optional - defaulting to an uninitialised value in the
"normal" case and a "1" in the "number of elements" case.

Someone should clear this up in the docs and submit a pull request :)

Cheers
Ben

hackspanner <hacks...@gmail.com> writes:

> Ah, I see. So then the ptr is allocated on the heap with halloc?
>
> On Wednesday, April 20, 2016 at 9:58:10 PM UTC-7, Dr Offig wrote:
>>
>> Hi Dave, the syntax for (bind-val) is a bit different to the way you are
>> using it. The syntax (or perhaps semantics) depends on whether you are
>> binding a pointer value or a normal value.
>>
>> Normal: (bind-val *<variable-name>* <*variable-type*> <*value*>)
>> Pointer: (bind-val <*variable-name*> <*variable-type*>* <
>> *number-of-elements-to-allocate*>)
>>
>> So, your first line should be (bind-val ptr i32* 1) if you just want a
>> single pointer.
>>
>>
>>
>>
>>
>> On Thu, Apr 21, 2016 at 2:47 PM, Ben Swift <b...@benswift.me <javascript:>
>>> email to extemporelan...@googlegroups.com <javascript:>.

Andrew Sorensen

नपढिएको,
२०१६ अप्रिल २१, ०६:१९:१५१६/४/२१
प्रापक extemp...@googlegroups.com, Ben Swift, Hack Spanner
Hi Dave,

This is a bug, could you write up your example as an issue on github for us.

Cheers,
Andrew
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

hackspanner

नपढिएको,
२०१६ अप्रिल २१, १६:४८:१५१६/४/२१
प्रापक Extempore, b...@benswift.me, hacks...@gmail.com
ok, will do.
सबैलाई जवाफ पठाउनुहोस्
लेखकलाई जवाफ
फर्वार्ड गर्नुहोस्
0 नयाँ म्यासेजहरू