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 [email protected].
To post to this group, send email to [email protected].
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.

Reply via email to