473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

What is padding and detecting it...

Facultas
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?
Apr 17 '07 #1
5 2064
RedSon
5,000 Expert 4TB
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.
Apr 17 '07 #2
JosAH
11,448 Expert 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. struct {
  2.    char dummy;
  3.       // <--- internal padding here
  4.    double d; // or int i, or short s or whatever
  5. } padding_t;
  6. ...
  7. printf("alignment of double: %d\n", offsetof(padding_t, d));
kind regards,

Jos
Apr 17 '07 #3
RedSon
5,000 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. struct {
  2.    char dummy;
  3.       // <--- internal padding here
  4.    double d; // or int i, or short s or whatever
  5. } padding_t;
  6. ...
  7. 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.
Apr 17 '07 #4
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:
Expand|Select|Wrap|Line Numbers
  1. struct {
  2.    char dummy;
  3.       // <--- internal padding here
  4.    double d; // or int i, or short s or whatever
  5. } padding_t;
  6. ...
  7. 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?
Apr 17 '07 #5
Banfa
9,065 Expert Mod 8TB
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.
Apr 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
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">...
2
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...
13
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...
17
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...
39
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...
4
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...
12
by: Kislay | last post by:
case 1 : struct s { char c1; // 8 double d; // 8 int i1; // 4 char c2; // 4 int i2; // 4 };
6
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...
52
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.