Forum > Beginners

My contribution to the community for beginners

<< < (5/5)

Gustavo 'Gus' Carreno:
Hey kveroneau,

This is a minor thing and it's just my unhealthy thing that I can't seem to shut up when I see failing things...

Welp, some of the code blocks have erratic syntax highlighting and I was wondering why is that?

Apart from this insignificant little mishap, the content is totally AWESOME and deserves a good pat on your back!!!!

Keep it on and this will be a very good repository of knowledge.

I also hope you manage to get it on GitHub so that the community at large can help you with some PR's

Cheers,
Gus

Bi0T1N:
The problem with

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TRequest = record    id: Integer;    op: byte;    data: string[80];  end;   TResponse = record    id: Integer;    status: byte;    data: string[80];  end;and

--- Quote ---I am not entirely sure why, but the structure in Python has a size of 85, but the same structure in Object Pascal has a size of 88.
--- End quote ---
is due to data alignment. To align the memory there are three hidden bytes added (padding) after the status byte: 4+1+3+80=88. If you want to avoid that, you need to use packed record and then the record will have a size of 4+1+80=85 as in Python.

winni:
Hi!

If you use the packed record it will use 86 bytes:

The string[80] is a shortstring, a so called "Pascal string".
It carries in the byte zero the length, so the string[80] occupies in the packed mode 81 byte.

Winni

Bi0T1N:

--- Quote from: winni on June 26, 2021, 05:38:14 pm ---The string[80] is a shortstring, a so called "Pascal string".
It carries in the byte zero the length, so the string[80] occupies in the packed mode 81 byte.

--- End quote ---
Indeed, wasn't aware of that. :-[
However, for such things it's better to use arrays with fixed length like array[0..79] of byte. The same applies for the integer variable since it might not have the same amount of bytes on all platforms. Better prefer fixed width integers like Int32 (will always have 4 byte).


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TRequest = packed record    id: Int32;    op: byte;    data: array[0..79] of byte;  end;type  TResponse = TRequest;

Navigation

[0] Message Index

[*] Previous page

Go to full version