473,776 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2201
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!@!digita lnothing.com> wrote in message news:uJ******** ******@tk2msftn gp13.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******** ********@TK2MSF TNGP12.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!@!digita lnothing.com> wrote in message news:OI******** ******@TK2MSFTN GP09.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******** ********@TK2MSF TNGP12.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
3716
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 send across data to the server in a serialised stream. However, when I need to geta response back to the client (.Net), I get a binary stream. What I wanna do is to convert this stream into an SByte array (The java byte is actually a signed byte,...
3
1312
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 below... --
2
24895
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 sbyte as -1. The BitConverter class only takes 2 byte arrays or larger, and the Convert.ToSByte simply throws an overflow error. Any ideas? Thanks, Ray Ackley
1
12546
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 method for converting an array of sbytes to an array of bytes? Thanks, Darrel
5
8516
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 this is appropriate. I am using the following sequence: // Load class Assembly c = Assembl.LoadFrom("filename ....); // Get the types cTypes = c.GetTypes();
3
6407
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 way to pass sbyte array to stream classes eg: memory stream?
0
1395
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 languages, the member functions of your ref class should accept parameters of type System::String^. The C++/CLI compiler provides some pretty simple methods for getting the data as native C++ characters if you need to, for example the...
2
1379
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 stand there with an int, which is wrong
1
2207
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); Any help is appreciated. Thanks and have a great day! Cheers,
0
9628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8954
agi2029
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...
1
7471
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 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...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
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...

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.