value() from local variables

value() from local variables


I'm trying to convert arbb scalar types into c++ types inside an arbb call(). But i don't know how to do this, calling value() throws the following exception during runtime:

terminate called after throwing an instance of 'arbb_2::exception'
what(): Extracting values from local variables is not allowed.

code snippet:


void foo(arbb::u16& x) {
	int i = value(x);
	//do stuff with i

int main(int argc, const char* argv[])
	arbb::u16 bar(5);

Besides: how do I convert between scalar types e.g. usize and u16?


8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Thanks for your post. I do not recommend feeding anything into array functions but very large arrays. There's no benefit to doing scalar work inside an ArBB function - there won't be anything to parallelize. Given the realities of dynamic compiliation, you need to not only feed a large amount of data into an ArBB function, and have that function called many times to justify the JIT compilation overhead, but also be doing a lot of computation inside to allow for good runtime optimizations. Second, to address your problem, take a look in the User's Guide concerning the proper signature for an ArBB function along with the list of scalar types and their corresponding ArBB type. You then need to createa dense container of that type using either the bind or range interface.The dense containers that are returned after calling an ArBB function,the one(s) with the ampersand, actually don't need any conversion back to C++ in the case of binding - the C++ data structure and ArBB data structure are duals of one another sharing the same memory space. If you used range to create the dense container, you could then use value to get the C++ type, but it can't be inside an ArBB function. Why?? Because everything inside ofan ArBB function isevaluated at runtime and only ArBB types and operationsare evaluated. All C++ code is inlined.Since the value() treds the line between ArBB and C++, it did not make sense for us to allow extractingthe value inside the ArBB functionat runtime.

Thanks for replying! I know that my example didn't make much sense in terms of efficiency, it was just the most simple example I could come up with to demonstrate the problem.

My actual program does something more like this:


std::string s1="string1";
std::string s2="string2";

void mymap(arbb::u16& x) {
	arbb::usize pos;
	_if(s1[pos] == s2[pos])//no operator[] for arbb::usize, value(pos) also doesn't work

void foo(arbb::dense& x)

int main(int argc, const char* argv[])
	arbb::dense bar(s1.size());

So I try to decide which computation to do based on a string comparison, and need to somehow feed the current position() into a string operator[]. Is that somehow possible?



Could you provide the definition of position() along with a summary of what it does?

that's the arbb::position function:

void arbb::position
usize &

Returns the current position of an arbb::map() invocation into {col, row, page}.

Best Reply

Using value() is not allowed in captured code. Converting from arbb types to C++ types (e.g. from u16 to int) is also not allowed.

To achieve whatyou want to do inthe 2nd example,you need to use ArBB denses of u8 type (that is, arbb::dense), and use the two std::strings to initialize the ArBB denses (through either the bind interface or the range interface). Remember, ArBB functions can only deal with ArBB types. Operating on std::string type inside an ArBB function does not work.

Hi Marc,

the state of any ArBB variable (from inside an arbb::call) is not accessible to the C++ code. The code that is generated by your C++ compiler (static code) is not part of the jitted code (runtime-dynamic code). The C++ code (inside of an arbb::call'ed function) just helped to describe an ArBB-program (read this again ;-).

How to better understand this "C++ code vs. jitted code" topic? Well, the application code A creates a state SA while it runs, and the jitted code B generates a state SB while it runs (the state of a program is determined by the values of your variables). Both states, SA and SB are on their own with only well-defined interchange. For example:

  • B only takes function arguments of A.
  • B may refer state of A at the time when B is generated;
    (this SA is baked-in as a constant into B).
  • A may only take state of B via a function return value;
    (non-const function argument).

- Hans

"An iterator is not a number it is an object that most of the times does not take a number as a constructor parameter.Just replace the line with Viterator pCurrent = Viterator();
It will missbehave in the same way the current code doe"

Leave a Comment

Please sign in to add a comment. Not a member? Join today