January 2020
Intermediate to advanced
532 pages
13h 31m
English
Before we conclude this section, there is yet another alternative to keep the flexibility of global variables while not losing too much performance. We can call it a global variable placeholder.
As it may have become clear to you by now, Julia can generate highly optimized code whenever the type of a variable is known at compilation time. Hence, one way to solve the problem is to create a constant placeholder and store a value inside the placeholder.
Consider this code:
# Initialize a constant Ref object with the value of 10const semi_constant = Ref(10)function add_using_global_semi_constant(x) return x + semi_constant[]end
The global constant is assigned a Ref object. In Julia, a Ref object is ...
Read now
Unlock full access