lykos

lykos

Representation of big integer in heap - connection between the header and data words

Hey all,
I was looking into the representation of big integers as boxed terms in heap. I understood how the header word and data words contain information in bits. But I couldn’t figure out how the header word is connected to the data words. Will the immediate term containing the pointer in stack refer to both header word and the first data word or will the data words be always contiguously stored after the header word. Any help would be appreciated.

Thank you.

Marked As Solved

garazdawi

garazdawi

Erlang Core Team

The data words will always be contiguously stored after the header word. This is the way it works for all boxed terms.

Also Liked

al2o3cr

al2o3cr

The code stores “digits” the size of a machine word, and keeps the count for those in the upper bits of the header.

Some good places to read in the OTP source:

  • otp/erts/emulator/beam/erl_term.h: a nice diagram of how tags are used in a term’s header. A bignum’s sign is stored in the tag.
  • otp/erts/emulator/beam/big.h: some C macros that access different parts of a bignum:
    • the sign is in the lowest bit of the header
    • the digits all immediately follow the header (the +1 in BIG_V)
    • the arity (number of digits) is stored in the header
  • otp/erts/emulator/beam/big.c: the implementation of most bignum functions. The link goes to I_comp which tells us about how digits are stored
    • the first two cases dispose of the easy parts, when one number is more digits than the other
    • the final case does the digit-by-digit comparison, starting from the digit farthest from the header as indicated by setting up the loop with x += (xl-1)

One final thing - normally I’d point people towards the BEAM Book which has an epic amount of internal detail, but alas the section on bignum representation is marked TODO :crying_cat_face:

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement