|
Yes an instance of System.Int32 occupies exactly 4 bytes in memory when it is allocated on the stack.
Yes an instance of System.Int32 is also a System.Object and if the CLR needs its object
behavior, the compiler will have provided the necessary code to make it act as an object,
but that does not change the data foot print.
Example:
int a=12;
string s=a.ToString();
the ToString() method applies to "object" a, the compiler will allocate a 4B integer on stack
and generate code that calls System.Int32.ToString().
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Bravo! That is the best explanation yet.
This is exactly what MOST of my colleagues believe. The devils advocate of the group maintains that:
int a=12; // is not a ValueType until
string s = a.ToString() // is called
Thanks everybody for your input.
|
|
|
|
|
Well, most of your colleagues are right.
It suffices to compile some code and look at the generated MSIL (e.g. with ILDASM)
to observe an int is simply an int, and some class methods get called when appropriate.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I am sorry my answer:
"Yes, an integer will only take 4 bytes."
could leave you in doubt how much memory an integer takes, though I have no idea what so ever how it could be written clearer. And no, my explanation does obviously not imply that more data is stored than the 4 bytes.
I do not know what you mean with "more information available" - yes, obviously it has. Every single object ever created has more information available than the bytes it takes up in memory (as it can easily access the information for the class itself). Or maybe you are referring to the information built into the CLR allowing it to do the boxing/unboxing - sure there is information available for that as well, but obviously per class, not per object, so it does not affect the amount of bytes each object use.
With regards to:
int a=12; // is not a ValueType until
string s = a.ToString() // is called
it probably goes on details in the CLR. "a" is not boxed before the a.ToString call, but at any time "a is ValueType" would return true, and at any time it can be used as a ValueTime. Hence I would consider it a ValueType no matter how it happens to be represented in memory, but I can see the other side of the argument as well - it all comes down to seeing it from the level of C# or from the level of the CLR implementation.
|
|
|
|
|
Also, this is valid:
string s = 12.ToString();
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
And VS will show "Int32" tooltip when you hover over that 12
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
hi friends,
I am building an application in asp.net in which my task is to create a pdf file by using the Adobe Indesign CS2 in asp.net.
I am using the code which is found from the net but on running this is given an error That:
"System.UnauthorizedAccessException: Access is denied."
now tell me about this error and what i have to do to achieve this task.
atleast reply if u don't know the answer also please.......
Here's my code::
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
' Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports InDesign
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cstrInddFile As String = Server.MapPath("~/Archieve/yourstory_backcover1.indd")
Dim cstrXMLFile As String = Server.MapPath("~/Archieve/xml1.xml")
Dim cstrOutputFile As String = Server.MapPath("~/Archieve/out.pdf")
Dim indAppType As Type = Type.GetTypeFromProgID("InDesign.Application")
Dim objInDesign As InDesign.Application = DirectCast(Activator.CreateInstance(indAppType, True), InDesign.Application)
Dim objDoc As InDesign.Document = DirectCast(objInDesign.Open(cstrInddFile, False), InDesign.Document)
objDoc.ImportXML(cstrXMLFile)
Dim objPreset As InDesign.PDFExportPreset=DirectCast(objInDesign.PDFExportPresets.LastItem(),InDesign.PDFExportPreset)
objDoc.Export(idExportFormat.idPDFType, cstrOutputFile, False, objInDesign.PDFExportPresets("Press"))
End Sub
End Class
-- modified at 7:21 Thursday 18th October, 2007<b></b>
|
|
|
|
|
gopal_Pandey wrote: this is really urgent one
It's always urgent. Still kudos for not putting urgent in your post title.
Anyway - your problem here is that the user that the website is running under doesn't have access to the file. This is down to permission restrictions - so you need to allow the website user (that's the user identity the website runs under) read/write permissions on the relevant directory.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Please don't email me direct. Doing this prevents others from following the thread.
Anyway - to answer your question, I have already given you a hint as to what to do. Check the permissions of the directory and see whether or not the ASP worker process has read/write access to it. I don't know how much more explicit I can be without actually coming round and doing it for you.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi everyone,
Sorry for that Email Mr Pete O'Hanlon,
I got your answers but all of you telling me only one solution which i have solved out i have given access to that file and also allowed the whole files to access rights what u have told me but it doesn't solve any problems....
I am using a trial version which is not registered of Adobe Indesign CS2.....
Please think again about this and reply me
i am waiting for your answers.......
bye........
|
|
|
|
|
Hi Friends,
Using .NET 2.0 how do I extract .zip file? It seems GZipStream does not go well. Is there any other class in .NET where in can be used to extract .zip file?
Thanx in advance.
Regards,
Vipul Mehta
Sr. Software Engineer
Accenture Services Pvt Ltd
|
|
|
|
|
|
Thanx for the links but I am suppose to use microsoft class liabraries only.
Regards,
Vipul Mehta
|
|
|
|
|
Hi,
In the java.utils.zip include tools that should help JAVA developers in .NET
But, one of the grate features there, that i can't understand why it isn't part of the common BCL is the zip file support.
First, add vjslib.dll and vjslibcw.dll as reference.
If you can't find them, ther are in J# Package: Here[^].
Use ZipFile Class to zip and unzip files.
|
|
|
|
|
Hi,
After implementing the following logic I get "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream." error
string sourceFile = @"C:\Test\MyDocs.zip";
string destinationFile = @"C:\Test";
if (File.Exists(sourceFile) == false)
{
return;
}
FileStream sourceStream = null;
FileStream destinationStream = null;
GZipStream decompressedStream = null;
byte[] quartetBuffer;
int position;
int checkLength;
byte[] buffer;
try
{
sourceStream = new FileStream(sourceFile, FileMode.Open);
decompressedStream = new GZipStream(sourceStream, CompressionMode.Decompress, true);
quartetBuffer = new Byte[4];
position = Convert.ToInt32(sourceStream.Length) - 4;
sourceStream.Position = position;
sourceStream.Read(quartetBuffer, 0, quartetBuffer.Length);
sourceStream.Position = 0;
checkLength = BitConverter.ToInt32(quartetBuffer, 0);
buffer = new byte[checkLength + 100];
int offset = 0;
int total = 0;
while (true)
{
int bytesRead;
bytesRead = decompressedStream.Read(buffer, offset, 100);
if (bytesRead == 0)
{
break;
}
else
{
offset += bytesRead;
total += bytesRead;
}
}
// Now write everything to the destination file
destinationStream = new FileStream(destinationFile, FileMode.Create);
destinationStream.Write(buffer, 0, total);
// and flush everyhting to clean out the buffer
destinationStream.Flush();
}
catch (Exception ex)
{
}
finally
{
// Make sure we allways close all streams
if (sourceStream != null)
{
sourceStream.Close();
}
if (decompressedStream != null)
{
decompressedStream.Close();
}
if (destinationStream != null)
{
destinationStream.Close();
}
}
Can any body help me out?
Regards,
Vipul Mehta
|
|
|
|
|
Are you absolutely sure your .zip file is in gzip format? The gzip format has a header and the GZipStream class accounts for this. But, if your .zip file is not in gzip format, the gzip decompression will not work.
Your .zip file may have been created with the DEFLATE compression method in which case you need to use the DeflateStream class.
Simply substitute GZipStream with DeflateStream and see what happens...
|
|
|
|
|
I am trying to unzip an container .zip file (it contains many files & folder within that). My app. downloads this .zip file from an http URL of an web site & then tries to unzip it.
After implementing DeflateStream class, it shows me following error:
"Block length does not match with its complement"
Regards,
Vipul Mehta
|
|
|
|
|
ZIP is not GZip. They are different formats. GZip compresses a single stream of bytes, ZIP is a container for multiple files each of which can be compressed a different way (although conventionally the Deflate algorithm is used, unless that gives no compression in which case the original file is simply stored instead).
The ZIP format is documented[^]. Parsing it is actually pretty easy.
SharpZipLib does work but I've found it pretty slow.
The GZipStream and DeflateStream classes are primarily intended for the web support e.g. HttpWebRequest, because the HTTP protocol allows responses to be compressed. Java has ZIP classes because its class library format, JAR, is simply a renamed ZIP file. (An individual class's bytecode is stored in a .class file, early versions of Java did not allow you to bundle these up into a package, later versions added the Java ARchive, JAR, format.)
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
Hello,
I have code in VC++ with MFC.Can I develop the same code in .NET framework.
What major changes will be required in the VC++ code.
Prithaa
|
|
|
|
|
Well - if you're dealing entirely with the .NET framework, then pretty much every bit of your MFC code is going to change. If it works as MFC, why change it?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
If you are developing new code, why waste time with a 15 year old API like MFC.
If you are trying to use existing MFC code, you can host your MFC code in WPF through the interop mechanisms.
Only you can weigh the cost between salvaging MFC code or re-writing it in Windows Forms or WPF.
|
|
|
|
|
Hello,
Thanks for your support.
Where will I find the details of hosting MFC code in WPF ?
Can you give me the link.
Prithaa
|
|
|
|
|
I'm a book worm, myself...
Windows Presentation Foundation Unleashed - Adam Nathan
Essential Windows Presentation Foundation - Chris Anderson
|
|
|
|
|
Is there some utility that can scan an assembly and spit out any methods that are being used that are not .netcf compliant?
Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt
|
|
|
|
|
netcf means .NET Compact Framework? And by compliant you mean API's being used?
Could you use the decompiler utilities to produce code, then put it in a CF project and compile it?
|
|
|
|