intsize;elsewhere

mysql - int(11) vs. int(anything else) - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
J it only takes a minute:
I'm new to web programming and doing different tutorials that I can find on the net.
I did my research and found out that in int(11), 11 is the maximum display width for integers and it's the default value if unless the integer is UNSIGNED (in this case it's 10).
When I see something like this:
id INT(11) not null AUTO_INCREMENT
I have no questions. But why do I see different things in different tutorials? For examlpe, in some, it says,
id INT(10) not null AUTO_INCREMENT
id INT(4) not null AUTO_INCREMENT
What are the authors of those tuts trying to achieve? None of them seem to bother to give an explanation what 10 or 4 means.
Alright, they're obviously reducing the display width, but why? What's wrong with the default width of 11? Why would they want to change it? Or are there any other reasons I don't know of?
The x in INT(x) has nothing to do with space requirements or any other performance issues, it's really just the display width. Generally setting the display widths to a reasonable value is mostly useful with the UNSIGNED ZEROFILL option.
//INT(4) UNSIGNED ZEROFILL
//INT(2) UNSIGNED ZEROFILL
Without the UNSIGNED ZEROFILL option the value will be left-padded with spaces to the appropriate display width.
63.3k18108155
The number is just a representational option called "display width". It may be used by some applications to pad the field when displaying numeric datatypes.
The int size is neither bits nor bytes. It's just the display width, that is used when the field has ZEROFILL specified.
explains the meaning of int(size) in MySQL.
"This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)"
That is, int(4) is politely asking that 123 be displayed as " 123".
Don't know how many things actually pay attention or why they'd bother in a tutorial.
"The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly."
So if you shove 123456 into an int(4) it will still be 123456.
Nothing to do with disk space or performance, just a hint to the application retrieving the data that it would like to be displayed with at least N digits.
The related ZEROFILL option can be used in conjunction to actually pad out the returned data.
So 123 in an int(4) ZEROFILL is returned as 0123.
63.6k1276186
Yes it specifies the display width, and this comes into play only when ZEROFILL is specified. So at that time it can pad the field value with the required number of zeros.
I agree that the MySQL manual is a little vague on the length/display width of integers. You might think that this limits the value you can store in the column to the number of digits but the valid range of the colomn doesnt change, wether you set it to 1 or 11.
What it really does is determine the display width of the column's value. The only case this is usefull is if you use ZEROFILL to pad your values with zero's.
So basically there is no real difference between INT(1) and INT(11) in terms of what you can store in the column, the only case when it becomes relevant is when you want to ZEROFILL your values.
More info:
10.5k85291
Copying from this :
MySQL has a little know feature for numerical types known as zerofill. This feature effects the display size of numerical types. Unlike the string types the number inside the parentheses is not the storage size in characters for the type. For numerical types the type name itself determines storage size.
The integer type it’s the padding size for zerofill.
46.5k27108171
It's not performance increase neither difference in maximum allowed size.
It's only used when ZEROFILL is applied on that column. (See: )
4,34473878
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .24755
Stack Overflow works best with JavaScript enabledA MeasureSpec encapsulates the layout requirements passed from parent to child. Each MeasureSpec represents a requirement
for either the width or the height. A MeasureSpec is comprised of a size and a mode. There are three possible modes:
UNSPECIFIED  The parent has not imposed any constraint on the child. It can be whatever size it wants.EXACTLY  The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be.AT_MOST  The child can be as large as it wants up to the specified size.
1.使用&View.resolveSize(int size,int measureSpec)
public static int resolveSize(int size, int measureSpec) {
int result =
int specMode = MeasureSpec.getMode(measureSpec);
int specSize =
MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
case MeasureSpec.AT_MOST:
result = Math.min(size, specSize);
case MeasureSpec.EXACTLY:
result = specS
public static class MeasureSpec {
private static final int MODE_SHIFT = 30;
private static final int MODE_MASK
= 0x3 && MODE_SHIFT;
public static final int UNSPECIFIED = 0 && MODE_SHIFT;
public static final int EXACTLY
= 1 && MODE_SHIFT;
public static final int AT_MOST
= 2 && MODE_SHIFT;
public static int
makeMeasureSpec(int size, int mode) {
return size +
public static int
getMode(int measureSpec) {
return (measureSpec & MODE_MASK);
public static int
getSize(int measureSpec) {
return (measureSpec & ~MODE_MASK);
int measureSpec = makeMeasureSpec(4, EXACTLY);
getSize(measureSpec);
getMode(measureSpec);
-----------------------makeMeasureSpec --------------------- mode+size
mode: & & & & & & & & &size:                        & & & & & & & &100measureSpec:
---------------getMode &---------------- MODE_MASK & measureSpec
MODE_MASK: & & & &measureSpec: & & & &
3.示例ListView.measureItem(View child)
private void measureItem(View child) {
ViewGroup.LayoutParams p = child.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec,
mListPadding.left + mListPadding.right, p.width);
int lpHeight = p.
int childHeightS
if (lpHeight & 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
child.measure(childWidthSpec, childHeightSpec);
&4.重写ListView与ScrollView 兼容:
protected void&onMeasure&(int widthMeasureSpec, int heightMeasureSpec)
Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE && 2, MeasureSpec.AT_MOST);
  super.onMeasure(widthMeasureSpec, expandSpec);
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Sets up mListPadding
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int childWidth = 0;
int childHeight = 0;
mItemCount = mAdapter == null ? 0 : mAdapter.getCount();
if (mItemCount & 0 && (widthMode == MeasureSpec.UNSPECIFIED ||
heightMode == MeasureSpec.UNSPECIFIED)) {
final View child = obtainView(0);
measureScrapChild(child, 0, widthMeasureSpec);
childWidth = child.getMeasuredWidth();
childHeight = child.getMeasuredHeight();
if (recycleOnMeasure()) {
mRecycler.addScrapView(child);
if (widthMode == MeasureSpec.UNSPECIFIED) {
widthSize = mListPadding.left + mListPadding.right + childWidth +
getVerticalScrollbarWidth();
if (heightMode == MeasureSpec.UNSPECIFIED) {
heightSize = mListPadding.top + mListPadding.bottom + childHeight +
getVerticalFadingEdgeLength() * 2;
if (heightMode == MeasureSpec.AT_MOST) {
// TODO: after first layout we should maybe start at the first visible position, not 0
heightSize = measureHeightOfChildren(widthMeasureSpec, 0, NO_POSITION, heightSize, -1);
setMeasuredDimension(widthSize, heightSize);
mWidthMeasureSpec = widthMeasureS
Views(...) Comments()

我要回帖

更多关于 else什么意思 的文章

 

随机推荐