### Author Topic: Point pair and list in memory  (Read 1272 times)

0 Members and 1 Guest are viewing this topic.

#### baitang36

• Bull Frog
• Posts: 212
##### Point pair and list in memory
« on: January 05, 2022, 11:55:15 PM »
Point pair is a special kind of list
(setq a (cons 1 2))
Return (1 . 2)
(setq a (cons 2 nil))
Return (2)
(setq a (cons 1 '(2)))
Return (1  2)
The point pair (1 . 2) is in memory as follows:
D0 0C DF 0B 00 00 00 00 03 00 00 00 05 00 00 00
In a 32-bit system, it takes up 16 bytes
D0 0C DF 0b is a mark indicating that the data structure is a cons
00 00 00 00 reserved, function unknown
03 00 00 00 is an integer 1. The relationship between the value in memory and the integer value is 2n + 1, 1 becomes 3, 2 becomes 5  ,   100 to 201
05 00 00 00 is an integer 2

'(2) this is a list with only one atom. It is in memory as follows:
D0 0C DF 0B 00 00 00 00 05 00 00 00 00 00 00 00
It can be regarded as a point pair (2 . Nil)
(setq a '(2 . Nil)) returns (2)
that list (2) and point pair (2 . Nil) are equivalent.

list  '(1 2) occupies 32 bytes in memory, which uses twice as much memory space as (1 . 2)

D0 0C DF 0B 00 00 00 00 03 00 00 00 68 9A DF 0D
D0 0C DF 0B 00 00 00 00 05 00 00 00 00 00 00 00
list (1 2) can be regarded as a linked list composed of two point pairs
68 9A DF 0D is an address, which is the second atom of the first point pair and the address of the second point pair.

The return value of (setq a (cons 1 '(2 . Nil))) is table (1 2)
Similarly, the list (1 2 3) will occupy the memory space of three point pairs

(setq a (cons 1 2))

(setq a (cons 2 nil))

(setq a (cons 1 '(2)))

D0 0C DF 0B 00 00 00 00 03 00 00 00 05 00 00 00

D0 0C DF 0B是一个记号，说明这数据结构是一个cons
00 00 00 00保留，功能未知
03 00 00 00是整数1，内存中的值和整数值的关系是2n+1,1变成3,2变成5,100变成201
05 00 00 00是整数 2

'(2)这是只有一个原子的表，它在内存中是这样：
D0 0C DF 0B 00 00 00 00 05 00 00 00 00 00 00 00

(setq a '(2 . nil)) 返回(2)

D0 0C DF 0B 00 00 00 00 03 00 00 00 68 9A DF 0D
D0 0C DF 0B 00 00 00 00 05 00 00 00 00 00 00 00

68 9A DF 0D 是个地址，它是第一个点对的第二个原子，也是第二个点对的地址。
(setq a (cons 1 '(2 . nil)))的返回值就是表（1 2）

« Last Edit: January 06, 2022, 08:34:02 PM by baitang36 »

#### Lee Mac

• Seagull
• Posts: 12857
• London, England
##### Re: Point pair and list in memory
« Reply #1 on: January 06, 2022, 08:21:08 AM »
Very interesting to observe these differences at the memory level, thank you for sharing.

#### baitang36

• Bull Frog
• Posts: 212
##### Re: Point pair and list in memory
« Reply #2 on: January 06, 2022, 08:23:48 PM »
Very interesting to observe these differences at the memory level, thank you for sharing.
I found an interesting phenomenon. Some of the functions you write will make mistakes after compilation and then decompilation. They are naturally resistant to decompilation. It may be that the existing decompilation tools are not considerate.
« Last Edit: January 06, 2022, 08:28:08 PM by baitang36 »

#### JohnK

• Seagull
• Posts: 10412
##### Re: Point pair and list in memory
« Reply #3 on: January 06, 2022, 09:56:06 PM »
It's amazing to see numbers that big! 8bytes per...wait! So "compiling" is just encryption (-i.e. character substitution).

BTW, What is the max/min value of a number (what is the largest number a number can be)?
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

#### It's Alive!

• Retired
• Needs a day job
• Posts: 8419
• AKA Daniel
##### Re: Point pair and list in memory
« Reply #4 on: January 06, 2022, 11:04:06 PM »
It's amazing to see numbers that big! 8bytes per...wait! So "compiling" is just encryption (-i.e. character substitution).

BTW, What is the max/min value of a number (what is the largest number a number can be)?

The memory layout for a buffer should be INT_PTR for next pointer, + int16_t (for the type code) + a 128bit union for data

RTLB, RTSHORT, 1, RTDOTE, RTSHORT, 2, RTLE, would make  ‘(1 . 2)  in arx, that’s actually 5 buffers, with RTLB, RTDOTE and RTLE having no data in the union.
It could be those are optimized out in VLX

in theory, you can store a 128bit value, though some packaging might be required

#### JohnK

• Seagull
• Posts: 10412
##### Re: Point pair and list in memory
« Reply #5 on: January 07, 2022, 09:15:24 AM »
Interesting!

My guess would have been:
Code - C: [Select]
1. union Data {
2.    int a;       // 1
3.    int b;       // 2
4.    char str[6]; // "( 1 . 2 )"
5. };
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

#### print1985

• Mosquito
• Posts: 2
##### Re: Point pair and list in memory
« Reply #6 on: January 09, 2022, 10:54:59 AM »
thank you for sharing
sheng lao shi 666

#### BOBO

• Mosquito
• Posts: 1
##### Re: Point pair and list in memory
« Reply #7 on: January 09, 2022, 11:07:57 AM »