Right,
Im trying to discover whether the machine my program is running on is currently using padding, and just to make sure im trying to find the right thing am i right in saying that padding is extra bytes added to the top of the stack that the stack can 'grow into'? And can it also be unused bytes added to a variable that has been put on a stack in order to make it conform to say, a 16 byte alignment for example? If this is right, is there any simple way of checking these?
5 2075 RedSon 5,000
Recognized Expert Expert
Right,
Im trying to discover whether the machine my program is running on is currently using padding, and just to make sure im trying to find the right thing am i right in saying that padding is extra bytes added to the top of the stack that the stack can 'grow into'? If this is right, is there any simple way of checking this?
Padding does mean adding extra bytes, but I have never heard it in reference to the stack. The call stack builds dynamically so adding padding to the stack would be redundant and not useful. Usually applications pad their memory requests and maybe the files that they write.
JosAH 11,448
Recognized Expert MVP
Padding (either internal or external) is all about alignment of data. Most
processors want their ints on a four byte boundary and their doubles on either
a four byte boundary or even an eight byte address boundary. You can find out
what padding your processor uses by checking this: -
struct {
-
char dummy;
-
// <--- internal padding here
-
double d; // or int i, or short s or whatever
-
} padding_t;
-
...
-
printf("alignment of double: %d\n", offsetof(padding_t, d));
kind regards,
Jos
RedSon 5,000
Recognized Expert Expert
Padding (either internal or external) is all about alignment of data. Most
processors want their ints on a four byte boundary and their doubles on either
a four byte boundary or even an eight byte address boundary. You can find out
what padding your processor uses by checking this: -
struct {
-
char dummy;
-
// <--- internal padding here
-
double d; // or int i, or short s or whatever
-
} padding_t;
-
...
-
printf("alignment of double: %d\n", offsetof(padding_t, d));
kind regards,
Jos
Good point. Some systems require that memory requests be on page boundaries. So when you request memory you have to request at least one page. You will also need padding for this type of memory request.
Padding (either internal or external) is all about alignment of data. Most
processors want their ints on a four byte boundary and their doubles on either
a four byte boundary or even an eight byte address boundary. You can find out
what padding your processor uses by checking this: -
struct {
-
char dummy;
-
// <--- internal padding here
-
double d; // or int i, or short s or whatever
-
} padding_t;
-
...
-
printf("alignment of double: %d\n", offsetof(padding_t, d));
kind regards,
Jos
Ah this is the same code (which is really useful btw :) ). you put into my alignment post. So padding is basically the unused bytes put in to 'pad' out the memory so that the variable being put into memory is aligned on the correct byte?
Banfa 9,065
Recognized Expert Moderator Expert
So padding is basically the unused bytes put in to 'pad' out the memory so that the variable being put into memory is aligned on the correct byte?
Yes. However in a structure using bit fields it can also be extra bits put into the structure (memory) so that the next field is aligned to the correct memory boundary.
It is possible (especially in embedded programming where ram tends to be more limited) to waste a significant amount of memory but poorly designing your structures and ending up with a lot of unrequired padding.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Stanimir Stamenkov |
last post by:
Here are two cases regarding inline-level elements' line-height,
padding and background, which I doesn't understand:
<div style="background: black; color: white; line-height: 1.5">
<span>Abc</span>
<span style="background: white; color: black; line-height:
3">Abc</span>
<span>Abc</span>
</div>
|
by: Knoxy |
last post by:
Hello, I've noticed one or two people post on this before but nobody
seems to have replied so raising the issue again... is this a known
IE6 CSS bug?
I have placed the following in my stylesheet file:
..formContentTable
|
by: Amarendra |
last post by:
Folks,
This structure padding issue is bothering me now, could
not locate a satisfactory answer on clc, so here it goes...
I have a structure, given below:
typedef struct {
int flag;
char keys;
char padding;
|
by: Mike |
last post by:
I'm trying to create a page: Three sections (left, topright and
bottomright), each with a heading and scrolling (overflow) content.
The size of these sections should be based upon the size of the user's
viewable area in their browser. I'm close... really close, but I'm
confused over how to mix specific measurements with percentages.
When I began, things were quite nice:
(http://play.psmonopoly.com/autosize.html). A little clunky in...
|
by: VidTheKid |
last post by:
THE PROBLEM
The % symbol is too vague when defining dimensions in CSS and HTML. It
can relate to an inherited value, a measure of the containing element
(which can differ between box models) or for background image
placement, the size of the element minus the size of the image.
A SOLUTION
There should be new %-like units defined in CSS to specify what the
measurement is a percentage of. These take the form of the % sign and
one or...
| |
by: _Raven |
last post by:
Okay, I am playing with submitting forms with Ajax. I am trying to adapt
this script to my forms:
http://www.captain.at/howto-ajax-form-post-get.php
I have included my code at the bottom of this post.
Basically, this will work correctly if I remove all non-form related tags
from the form =eg span, div, but I want to format the form all pretty like
so???
Right now, it only collects 2 parts of the form fields =sites &
|
by: Kislay |
last post by:
case 1 :
struct s
{
char c1; // 8
double d; // 8
int i1; // 4
char c2; // 4
int i2; // 4
};
|
by: maya |
last post by:
hi,
I recently discovered the hard way that when you had padding-right or
padding-left to a div it increases the with of the div... how do you
add left-padding or right-padding to a div w/o changing the width of it?
(for example: I have a div that's 320px wide, content inside is 300px
and I added padding-left:10px but it increased with of div to 330px.. I
want width of it to remain 320px but I need a padding on the left of 10px..)
|
by: marc |
last post by:
Hello,
Is it possible to right pad with "0" (or other character != blank) ?
for example :
1 , length 10 ="1000000000"
I've tried with sprintf but I can only left pad with "0" or right pad
with blanks =>
"0000000001"
"1 "
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |