473,385 Members | 1,317 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,385 software developers and data experts.

sbyte, int16, in32 all the same?

After downloading and using two different memory profiling applications
today, it seems that sbyte, int16, and int32 are all stored using 12b of
memory. Someone please tell me I'm reading these memory profilers wrong! If
I'm really reading it correctly, then what's the point of using anything
other than a 32 bit integer? If they're all going to be stored the same way,
then I can't achieve any memory savings(which I was really hoping for) by
using a short and an sbyte to store my necessary key/value pairs. Is there
any way to have these values stored as true 1b, 2b, or 4b datatypes?

Thanks,
Steve
Nov 15 '05 #1
3 2178
The minimum size of an object is 12 bytes, so you are right, both the key and value pair will occupy 12 bytes each irrespective the
type used. Note however that a minimum size object can hold 4 sbytes or 2 shorts or 2 bytes and a short.

Willy.
"Steve - DND" <steve!@!digitalnothing.com> wrote in message news:uJ**************@tk2msftngp13.phx.gbl...
After downloading and using two different memory profiling applications
today, it seems that sbyte, int16, and int32 are all stored using 12b of
memory. Someone please tell me I'm reading these memory profilers wrong! If
I'm really reading it correctly, then what's the point of using anything
other than a 32 bit integer? If they're all going to be stored the same way,
then I can't achieve any memory savings(which I was really hoping for) by
using a short and an sbyte to store my necessary key/value pairs. Is there
any way to have these values stored as true 1b, 2b, or 4b datatypes?

Thanks,
Steve

Nov 15 '05 #2
Thanks for the response, but I'm a little confused by the last sentence. Are
you saying that if I instantiate 4 sbytes(or bytes), that they will be
stored in the same 12 byte block of memory? If so does .Net do some kind of
automatic array creation behind the scenes to store these?

Thanks,
Steve
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The minimum size of an object is 12 bytes, so you are right, both the key and value pair will occupy 12 bytes each irrespective the type used. Note however that a minimum size object can hold 4 sbytes or 2 shorts or 2 bytes and a short.
Willy.

Nov 15 '05 #3
No the CLR (current version !!) will lay-out the object as four bytes stored into a single 4 byte word (an int on 32 bit machines).

So an instance of the class:
class Foo {
sbyte b1;
sbyte b2;
sbyte b3;
sbyte b4;
}

will occupy 12 bytes on the heap;
- an int used as sync block index,
- an int used as Method table pointer
- and the real object state, an int holding the four sbytes.

Willy.

"Steve - DND" <steve!@!digitalnothing.com> wrote in message news:OI**************@TK2MSFTNGP09.phx.gbl...
Thanks for the response, but I'm a little confused by the last sentence. Are
you saying that if I instantiate 4 sbytes(or bytes), that they will be
stored in the same 12 byte block of memory? If so does .Net do some kind of
automatic array creation behind the scenes to store these?

Thanks,
Steve
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The minimum size of an object is 12 bytes, so you are right, both the key

and value pair will occupy 12 bytes each irrespective the
type used. Note however that a minimum size object can hold 4 sbytes or 2

shorts or 2 bytes and a short.

Willy.


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nick | last post by:
Hi, Problem statement: Calling a java method from Dot Net code that returns a java byte array. Overview: I have a java server from which I need to establish connection. I hva ebeen able to...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
2
by: Ray Ackley | last post by:
I need to convert a byte to an sbyte - and it has to preserve the original binary meaning of the 8 bits. For example - a 1111 1111, which is interpreted as byte to be 255, should show up in the...
1
by: Darrel | last post by:
I am using binary writer to write an array of bytes to disk. However, my data starts out as an array of sbytes. I am currently type casting each array element in a for loop. Is there a faster...
5
by: Pat Ireland | last post by:
I am attempting to pass an SByte to another .NET class that expects the data to be passed as SByte *. I searched around and found the boxing can be used to produce a pointer but I'm not sure if...
3
by: reju | last post by:
I have to convert an sByte array to byte array. This sbyte array contains some signed values due to this .net converting functions will throw an exception.any work around for this? is there any...
0
by: Ben Voigt [C++ MVP] | last post by:
Chip Gore wrote: Actually, because you are using the C++/CLI compiler, microsoft.public.dotnet.languages.vc is the most appropriate place to discuss this. To be useful from C# and other .NET...
2
by: K Viltersten | last post by:
I try the following. sbyte HalvOfFour () { sbyte b = 4; return b / 2; } Apparently, since 2 is regarded as int, the operation upgrades my b to and int and after it has been performed, i...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
Dear All, Does anyone know the algorithm used to convert to an sbyte like follows? It is not a straight hex conversion. sbyte.Parse("B2", System.Globalization.NumberStyles.HexNumber, null); ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.