Here is an example:

http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/x2223.html

In your case,

the type message_Bar_pstruct(int, double) is for a pointer to BAR_

Here is a relevant example:

http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/x2223.html

You can find more in the following book by searching 'pstruct':

http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/INT2PROGINATS-BOOK-onechunk.html

Placement new operator in C++ can be simulated:

val Bar(int, double) = <some_uninitialized_node>
val () = int := 0 and double = 0.0

Hopefully, the boilerplate code can be compiler-generated in the future.



On Tue, Mar 20, 2018 at 2:35 PM, Andrew Knapp <andy.j.kn...@gmail.com>
wrote:

> Hello,
>
> I'd like to be able to send dataviewtypes as messages in a low-latency ipc
> library I've written.
>
> In this scenario, any use of malloc is unacceptable. Everything must be
> allocated from a memory pool or the stack, but datavtype constructors
> always allocate on the heap.
>
> What is the best way to access to the size and flat memory of the
> datavtype's tagged union, preferably in a typesafe manner? You can do this
> by a hack like
>
> dataviewtype message =
>   | Bar of (int, double)
>   | Baz of (double, double)
>
> #define BAR 0
> #define BAZ 1
>
> typedef BAR_ = @{
>   contag = int,
>   atslab__0 = int,
>   atslab__1 = double
> }
>
> typedef BAZ_ = @{
>   contag = int,
>   atslab__0 = double,
>   atslab__1 = double
> }
>
> and then using $UNSAFE.cast{Foo} on a pointer to stack or pool allocated
> memory of size FOO_SIZE = max(sizeof<BAR_>, sizeof<BAZ_>), which has had
> its contag set to BAR or BAZ via another unsafe cast.
>
> Unfortunately there is really a lot of boilerplate here and it will be
> easy for things to get out of sync with datatype definitions, especially
> with a lot of constructors. Moreover, FOO_SIZE is not a static constant, so
> you can't just write something like var buf : @[char][FOO_SIZE*N]
>
> Also, is there an equivalent of the placement new operator in C++?
>
> Thanks,
> Andrew
>
> --
> You received this message because you are subscribed to the Google Groups
> "ats-lang-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ats-lang-users+unsubscr...@googlegroups.com.
> To post to this group, send email to ats-lang-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/ats-lang-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ats-lang-users/51b38545-377a-445a-9e3c-2086e760a680%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/ats-lang-users/51b38545-377a-445a-9e3c-2086e760a680%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ats-lang-users+unsubscr...@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpAt8qUhvywYBvZpe8J1B5ObWvBz18KQeXVrDWYZUtqMw%40mail.gmail.com.

Reply via email to