LIGEnhancements - ListIconGadget with Grouping and TileView

Share your advanced PureBasic knowledge/code with the community.
User avatar
jacdelad
Addict
Addict
Posts: 1474
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: LIGEnhancements - ListIconGadget with Grouping and TileView

Post by jacdelad »

This makes no sense: The C-Code you provided plus the definition from Microsoft https://learn.microsoft.com/en-us/windo ... -lvcolumna don't indicate there's a padding. Also, it has no use.
I can neither explain your observation, nor understand it.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: LIGEnhancements - ListIconGadget with Grouping and TileView

Post by Denis »

jacdelad,

First of all,
i refer to structure LVCOLUMNW, W at the end indicates that is unicode one, if the is A, it means Ascci.

In C (h file definition), most of the time padding does not appear in definition, compiler do the job, that's why there is no padding.

Take a look to LVCOLUMN def from PB in x64
Structure LVCOLUMN
mask.l
fmt.l
cx.l
PB_Alignment.b[4]
*pszText
cchTextMax.l
iSubItem.l
iImage.l
iOrder.l
cxMin.l
cxDefault.l
cxIdeal.l
EndStructure
There is a padding after cx.l element, but this padding doesn't appear with C code but C compiler will align the structure correctly.
typedef struct tagLVCOLUMNW
{
UINT mask;
int fmt;
int cx;
LPWSTR pszText;
int cchTextMax;
int iSubItem;
int iImage;
int iOrder;
#if (NTDDI_VERSION >= NTDDI_VISTA)
int cxMin; // min snap point
int cxDefault; // default snap point
int cxIdeal; // read only. ideal may not eqaul current width if auto sized (LVS_EX_AUTOSIZECOLUMNS) to a lesser width.
#endif
} LVCOLUMNW, *LPLVCOLUMNW;
A+
Denis
User avatar
jacdelad
Addict
Addict
Posts: 1474
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: LIGEnhancements - ListIconGadget with Grouping and TileView

Post by jacdelad »

Ok, firstly, I know about W and A. :twisted: Unicode/ASCII doesn't matter here (yeah, yeah, String and WideString...).

But seriously, so C adds the padding automatically? For what? As per definition it is not used nor needed for anything.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: LIGEnhancements - ListIconGadget with Grouping and TileView

Post by Denis »

jacdelad,
No offence taken.

PB doc :
The special value #PB_Structure_AlignC can be used to align the structure as it would be done in language C, useful when importing C structures to use with API functions.
Instead of using #PB_Structure_AlignC, i do prefer create the structure with the padding.

Here you can see what compiler do for structure :
https://learn.microsoft.com/en-us/cpp/c ... w=msvc-170
Extract from the microsoft page, section of structures
Compilers attempt to make data allocations in a way that prevents data misalignment.

For simple data types, the compiler assigns addresses that are multiples of the size in bytes of the data type. For example, the compiler assigns addresses to variables of type long that are multiples of 4, setting the bottom 2 bits of the address to zero.

The compiler also pads structures in a way that naturally aligns each element of the structure. Consider the structure struct x_ in the following code example:
C++

struct x_
{
char a; // 1 byte
int b; // 4 bytes
short c; // 2 bytes
char d; // 1 byte
} bar[3];

The compiler pads this structure to enforce alignment naturally.

The following code example shows how the compiler places the padded structure in memory:
C++

// Shows the actual memory layout
struct x_
{
char a; // 1 byte
char _pad0[3]; // padding to put 'b' on 4-byte boundary
int b; // 4 bytes
short c; // 2 bytes
char d; // 1 byte
char _pad1[1]; // padding to make sizeof(x_) multiple of 4
} bar[3];

Both declarations return sizeof(struct x_) as 12 bytes.

The second declaration includes two padding elements:

char _pad0[3] to align the int b member on a 4-byte boundary.
char _pad1[1] to align the array elements of the structure struct _x bar[3]; on a 4-byte boundary.

The padding aligns the elements of bar[3] in a way that allows natural access.
A+
Denis
User avatar
jacdelad
Addict
Addict
Posts: 1474
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: LIGEnhancements - ListIconGadget with Grouping and TileView

Post by jacdelad »

Thanks Denis, I read this. And I think I understand some of what is said there. But this leaves still one serious question to me: Since the extra bytes are placed at the end, they are never used. So, the structure without this should work flawlessly too?!
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: LIGEnhancements - ListIconGadget with Grouping and TileView

Post by Denis »

jacdelad wrote: Tue Feb 27, 2024 8:46 am Thanks Denis, I read this. And I think I understand some of what is said there. But this leaves still one serious question to me: Since the extra bytes are placed at the end, they are never used. So, the structure without this should work flawlessly too?!
jacdelad,
this is a good question.

Just a point of clarification:
What I have written is for Windows with an Intel microprocessor.
Under Linux, I don't know or for other Microprocessors (ARM etc.).

The alignment is used for the speed of µp.

I don't know how Microsoft manage memory.
When writing value for the very last element, i don't know if a memory overwrinting couls occur.
A+
Denis
Post Reply