|
Rob Philpott wrote: I think its 12 bytes
IMO at run-time a reference is just a pointer, no more no less, hence 4 or 8B.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Agreed, just 4/8 bytes on the stack. But on the heap you get the extra eight bytes on top of the object itself. I think - not certain.
Someone, somewhere did a wonderful job of explaining it all here on CP.
Regards,
Rob Philpott.
|
|
|
|
|
|
Thanks. Too long to read right now.
In the mean time I think we understood the question in different ways.
"What is the size of a reference variable?" to me means "What is the size of a reference?" (hence 4 or 8B) and not "What is the size of an object?". Which I guess gets dealt with in the article; I hope it also mentions objects get aligned in memory, I think to a 32B boundary. So, assuming that is correct, the smallest object costs 32B of heap space.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: So, assuming that is correct, the smallest object costs 32B of heap space.
At the risk of really being quite boring, I was playing around with that the other day, trying to work out how much space a boolean takes as a class member variable.
Turns out the first one takes 32 bits, the second no bits, the third no bits, the fourth no bits, the fifth 32 again, etc. etc.
So, sort of one byte collectively rounded up to the nearest 32 bit word.
Regards,
Rob Philpott.
|
|
|
|
|
No surprise here. That is due to padding (inserting unused bytes, or rounding up the address), exactly like what happens when storing bytes in a C/C++/C# structure. By default elements of a struct (and the overall size of a struct) get word-aligned to prevent an access to the next 16-bit or larger quantity to cause a performance hit or an exception.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Cool.
Regards,
Rob Philpott.
|
|
|
|
|
Then why is it such a pain in the ass to convert references to IntPtr and vice versa (for using with platform invoke). As I understand it - IntPtr is a typical substitute for a general unmanaged pointer (int*, void*, ...), so why can't one use something like
SomeReferenceType instance;<br />
PInvokeCall((IntPtr) instance);
where PInvokeCall has signature
void PInvokeCall(IntPtr param);
No trolling, I am really curious about this.
|
|
|
|
|
A small object (small enough to be in a regular heap, not the large-object-heap) is a moving target: when the GC runs it can move it around to perform heap compaction. Managed code is fine with this, however your native code would not be aware of this, so the pointer could become invalid, unless the object got pinned first. That is exactly what the ref-to-ptr convertors ("fixed", GCHandle, Marshal) do.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi Guy
How can i Drag email of Outlook Express to Winform and Save to file .eml.
I can do it with Outlook 2003 and save to file .msg.
Anybody help me?
Thanks and best regards
Thien Nguyen
|
|
|
|
|
i'm looking hard for an answer to this as it is critical that I can drag from outlook express to winform app c#
mail me if you find and answer.
|
|
|
|
|
Hey guys, for some reason this stupid TCP server doesn't loop after a client disconnects from it. How can I have it continue to loop so when people do disconnect from it, it continues to accept connections. Here is the code.
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
public class serv
{
public static void Main()
{
int c = 1234;
try
{
IPAddress ipAd = IPAddress.Parse("69.10.61.145"); //use local m/c IP address, and use the same in the client
/* Initializes the Listener */
TcpListener myList = new TcpListener(ipAd, 7575);
/* Start Listeneting at the specified port */
myList.Start();
Console.WriteLine("Login Server is running.");
Console.WriteLine("Connection :" + myList.LocalEndpoint);
Console.WriteLine("Waiting for logins...");
Console.WriteLine("================================");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from: " + s.RemoteEndPoint);
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("Login Attempt Recieved from: " + s.RemoteEndPoint);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(b[i]));
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes("Login is invalid." + s.RemoteEndPoint));
Console.WriteLine("\nAccess Denied.");
Console.ReadLine();
return;
/* clean up */
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
Console.ReadLine();
}
}
}
[X] 100% HTML
[ ] 100% PHP
[ ] 100% C#
|
|
|
|
|
Either look up the async methods or wrap a while loop over the hart of the operation.
I personall recommend the async methds and they also nearly force you to do all the work in seperate methods, which actually comes in handy when you get used to it.
For the while loop, consider using a global bool value which you change when stopping to listen.
The while loop should cancel then and your application should continue.
Though, this doesn't really work as you may want to depending on how you build you loop.
In most cases it will still wait for a last connection to be made before it will finally break.
Start the loop before AcceptSocket call and end it when you're done, in this case below the Access Denied output.
I hope this helps a bit, TCP/IP is always confusing at the start...
|
|
|
|
|
I just wrapped while(true) around it, will that work? Also can you take a look at my other thread. its very important.
[X] 100% HTML
[ ] 100% PHP
[ ] 100% C#
|
|
|
|
|
I'd seriously recommend creating a new thread to handle the connection after you've accepted the incoming connection - that's the usual way these bits of code work. One thread just sits there and accepts connections, each time one comes in the socket is passed to a new thread to handle the conversation and the original thread carries on listening for subsequent connections.
What sort of server can only handle a single incoming connection? Also, take a look at TCPClient , it provides nicer access than Socket .
Regards,
Rob Philpott.
|
|
|
|
|
Hi,
Look at the following article[^], I think it might help you alot.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Is there a way to do it?
IE:
30000
I want it to be 30 000
|
|
|
|
|
You can use the .ToString() method to make it to a string.
There is a regexp function to do such a thing, but I forgot about it.
However, here is snippet that should do the trick aswell.
int number = 3000000;
int lengthPerSplit = 3;
string splitText = " ";
string result = number.ToString();
for (int index = result.Length - lengthPerSplit; index > 0; index -= lengthPerSplit)
result = result.Substring(0, index) + splitText + result.Substring(index, result.Length - index);
|
|
|
|
|
|
try this as a simpler solution, just keep adding sets of 3 #s
string.Format("{0:### ### ###.00}", 30000000);
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
string.Format is probably the easiest way to get any kind of formatting you want.
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
Hello all, I got a question and I unfortunatelly can't find a solution for it on the web.
I'm fairly sure it's out there, but probably I'm using the wrong criteria...
The main goal of this mini-project is, is to create 1 file with a GUI.
The user selects one of the options and the right executable will be launched.
Now there is no option to leave those executables outside of the entrypoint file and thus HAVE TO be embedded into it.
The embedding is not the problem, but the executing of the file is.
Since I don't want to save the file to the disc upon launching it and only will have a stream for it, it must execute it somehow from here.
I may be doing a comlete wrong approach, I'm open to anything that does what I want it to do:
1. Embed the file(s) to the main entrypoint file (this 1 big happy .exe file)
2. Execute a file without writing it to the HDD first and then execute it (the user may not be able to get the embedded .exe that easy).
I thank you for your time and hopefully you know a solution
Yours sincerely,
OsoreWatashi
|
|
|
|
|
OsoreWatashi wrote: Since I don't want to save the file to the disc upon launching it and only will have a stream for it, it must execute it somehow from here.
You can't. It has to be saved to disk. The Windows Loader will not start a new .EXE from a stream it does not know how to manipulate.
|
|
|
|
|
What a shame. They should add that. Windows could really use another attack vector.
|
|
|
|
|
Hi,
I´m looking for control like Corel Draw tool text editor or similar.
Do you know something like this ?
I´m using a Rich Text Box, but the font render is very diferent to font render of pdf library (iText),
( the RTB render text using GDI and iText render text using GDI+ )
I need write text, with any format ( font size, styles...), and then generate PDF document.
( what you see in screen must be identical in PDF )
somebody help me please
thanks!
|
|
|
|