|
You never said you were going to use the Jabber servers as your servers. Good luck with that!
You might want to read this so you get an idea of what you're getting yourself into: Jabber Client Programmer's Cheat Sheet[^]
|
|
|
|
|
What results did you rule out when you searched in Google? I would hate to duplicate work that you have already done. Does the Jabber site have any information?
|
|
|
|
|
With all these questions, it may help you to learn how to use Google; you will be amazed at how much time it saves you.
Use the best guess
|
|
|
|
|
If I want to serialize an object I have to use [Serializable] attribute and all member variables will be written to the file. What I don't know how to do versioning e.g. if I add a new member variable (rename a variable or just remove a variable) to the object e.g. m_dRadius and then I open (deserialize) the file how can I determine that the variable was initialized during the load or not.
I know that there are version tolerant approaches and I can mark variables with [OptionalField(VersionAdded = 1)] attribute. If I open an old file the framework will ignore this optional (new variable) and it will be just zero/null. But again how can I determine if the variable is initialized by load to zero or it was ignored.
I can write the class/object version number to the stream. Use the ISerializable approach and in the constructor(SerializationInfo oInfo, StreamingContext context) method read this version number. This will exactly tell me what is the class version in the stream.
However I expected that such kind of versioning is already implemented by the streaming framework. I tried to obtain the Assembly version from the SerializationInfo but it is always set to current version not to the version which was used when the object was saved.
What is the preferred approach? I found a lot of articles on the net, but I could not find a good solution for this...
Any help is appreciated
Thanks,
Abyss
|
|
|
|
|
Abyss wrote: What is the preferred approach?
If there was a preferred approach that applies in all circumstances, all other approaches would be dropped.
I'd go for the simplest solution; meaning the OptionalField if I'd expect that the class is not going to change much. Anything that could have more/complexer versions, I'd write a custom ISerializable.
Abyss wrote: However I expected that such kind of versioning is already implemented by the streaming framework. I tried to obtain the Assembly version from the SerializationInfo but it is always set to current version not to the version which was used when the object was saved.
It'd be overkill, and not everybody will be wanting to use those version-numbers. Keep in mind that the version-number you see is the one of the assembly that the class is contained in. Alternatively, one might use different version numbers for files, created with a single version of a class. So, the one-size-fits all wouldn't fit here.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i have very small programming experience. i heard about code optimization but do not know what it is. so i like to have good insight about code optimization that what it is and how people do the code optimization in real life. looking for good discussion and also redirect me to few good article which guide me to do the code optimization in real life. thanks
tbhattacharjee
|
|
|
|
|
I don't know of any "good sources" (well I know one, but it's pretty advanced), but I can give you a quick tour:
Profile everything. If you make any change to the part of the program you're optimizing, profile it again. Profile with realistic data - it can make all the difference. Don't bother with microbenchmarks, they're even harder to do right than normal benchmarking and they usually don't give a clear picture of how things behave in context. Besides, most likely, other people have already done them, so just look up the results.
Try out many different strategies. The algorithm that looks fastest on paper isn't always the fastest in practice, so be sure to try the "slow way" too, especially if it's much simpler or uses much less memory.
Ask for help often and/or search around for existing answers, and pay special attention to the explanation of why a certain thing is faster than an other.
After a while (could take some time) you'll get accustomed to the often counter-intuitive rules that determine what is fast and what isn't. Even then it'll be a constant battle of applying a new idea and benchmarking that, combining ideas and testing whether maybe together they help even if none of them helped individually, it'll still be hard and it will still take a lot of time, but you won't just be trying things blindly anymore.
On a more personal level, don't let people with "optimization is evil"-mindsets get to you. Their mindset is fueled by the constant attempts that people make to optimize the wrong thing incorrectly - as a beginner in the field of optimization, you will make that mistake. Everyone does. Ignore them, improve your skills, and eventually you won't make that mistake anymore. Or less often anyway, everyone makes mistakes now and then.
modified 26-Mar-13 5:57am.
|
|
|
|
|
Tridip Bhattacharjee wrote: i have very small programming experience
Then it is unlikely to be a good idea.
You need to know how to write "good" programs before you can understand how to make them more performant.
Requirements\architecture\design has far more impact on performance than any code optimizations will. So learning how to do the former well is going to have far more impact.
|
|
|
|
|
we know that when we declare static class then static class load in memory once when we run our apps. i was asked a wired question in interview and i could not explain very well. the question was 1) why we can not create instance of static class ? i will be glad if anyone explain in detail.
2) how memory is allocated for static class & why static class data stored in stack not in heap ?
looking for details discussion. thanks
tbhattacharjee
|
|
|
|
|
1) By definition.
2) What?
Those are horrible interview questions, I suspect they already decided they don't want you.
|
|
|
|
|
1) The purpose of a static class is to have only static methods... as I already explained on the other answer, extension methods require static classes, but a static method inside a static class or inside a normal class works the same way.
2) I think you are confusing static classes with value types. All the data on static classes uses normal allocation (heap). Only local variables are kept on the stack. But, as I said on the other answer, an int can be on the heap if it is part of another class, or it can be on the stack if it is a local variable (and actually this is not always true with anonymous delegates, but less forget about it).
A reference type (like a string) is always on the heap. But the "pointer" to such string follows the same principle as an int. So, a local string will have a reference on the stack and the real object on the heap. A string inside another object will have a pointer on the heap (the object which such string) and the string itself also on the heap, but at another place.
modified 25-Mar-13 12:13pm.
|
|
|
|
|
thanks for your time & answer.
you said :- Only local variables are kept on the stack.
an int can be on the heap if it is part of another class, or it can be on the stack if it is a local variable.
can u plzz explain with example or sample code which one will store when on heap and stack?
when int will store in heap and when on stack? i heard int is struct type and struct types are value type and they always store on stack. it would better if u please come with sample class code and explanation.
also tell me where actual value will store like Name="keith" Salary=25000 etc. thanks
tbhattacharjee
|
|
|
|
|
In any method...
int i = 5;
MyObject myObject = new MyObject();
myObject.intField = 10;
If you use unsafe code you can check the real size of objects by using the sizeof() operator. It will show you how many bytes such object will occupy. If it is a value type, that means how many bytes it will occupy where it is declared (if declared locally, it will be in stack... if declared inside another class, that will means how many bytes it will add to the size of instances of that class).
And to explain your question about Name and Salary.
If you have a class with both Name and Salary, the contents of such class will always be on the heap.
So, you will have:
Name = some address... 4 or 8 bytes (depending if the computer is 32 or 64 bits)
Salary = (if it is an int, then 4 bytes).
And that "some address" will in fact be where the "keith" object is contained.
There is where an important factor happens:
Imagine that you have 2 instances of your type that has name and salary, but both pointing to the same name.
Considering a 64 bits computer, each instance will have the normal object header (I think it is 16 bytes) + a string reference (8 bytes) + an int (4 bytes).
That is: 28 for each instance * 2 = 56.
But you will have "keith" only once in memory.
Again, this should be 16 + the length of the string * 2 + some info used by the string itself (I think it is only the hashcode, but I am not sure). That is: 16 + 10 + 4. Or 30 bytes only to contain "keith" in memory.
Now, if you have 100 references to "keith", the string reference will always stay at 8 bytes... so, 100 references = 800 bytes. But the string is only once in memory. Much better than having 30 * 100 (or 3000 bytes) for the strings.
|
|
|
|
|
|
I've been a bit confused when I wrote this. Nevermind, see my next post below, it contains all clarification which is neccessary.
modified 25-Mar-13 15:36pm.
|
|
|
|
|
i have a doubt that u said :- A static class is used when it makes no sense of having two classes. For example, if you write an application to calculate something, it simply makes no sense when you write.
in this case why do i need to create static class rather we can create static function inside in any non-static class and my purpose will be solved. i firmly believe that there must be some solid reason when user has to create static class. anyway thanks for ur time.
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: in this case why do i need to create static class rather we can create static function inside in any non-static class and my purpose will be solved.
No, think about the Directory-class in the .Net framework. Or the File-class. They are both static because they offer functionalities and not data.
Tridip Bhattacharjee wrote: i firmly believe that there must be some solid reason when user has to create static class.
I do too. IMO this happens as soon as a class shoulde provide functionalities instead of information.
|
|
|
|
|
u said : - think about the Directory-class in the .Net framework. Or the File-class. They are both static because they offer functionalists and not data.
it will be more help full for me if u come with sample code for static class which show me the importance of creating it instead of create a static method inside in any non-static class. thanks
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: it will be more help full for me if u come with sample code for static class which show me the importance of creating it instead of create a static method inside in any non-static class. thanks
Can we keep a normal conversation level with friendly sound? thanks.
I made a practical example. Since I am volunteer answering questions I kindly ask you to read Dave's link. It is nothing personal but I can't submit code for anyone asking for it. I personally mpostly do this when the OP has already submitted a bit of code to start fom.
|
|
|
|
|
you said to read Dave's link....but where it is ? thanks
tbhattacharjee
|
|
|
|
|
Here[^]. Right below this post.
|
|
|
|
|
|
A normal class is instantiated to an object and you can create many objects with that class. (thus you can see a class as a template for creating objects, each with its own properties)
A static class on the other hand cannot create objects at all. it can hold an algorithm (functions/methods) or some data, but it doesn't belong to anything.
Car red_car = new Car();
Car blue_car = new Car();
red_car.Speed = 100;
red_car.Color = Red;
blue_car.Speed = 65;
blue_car.Color = Blue;
red_car.Accelerate(-25);
blue_car.Accelerate(10);
double radius = 3.6;
double circumfence = MathConstants.CalculateCircleCircumfence(radius);
double americanpie = 3.141599999;
MathConstants.PI = americanpie;
The real world is less black and white than this, but I hope it makes some issues clearer for you.
|
|
|
|
|
most of the book never explain how memory is allocated for things we use.
i think no memory is allocated for class structure including member function and data member. memory is allocated when we create instance of class.....am i right ?
1) suppose if my class structure is like below one then just tell me how memory will be allocated ?
public class Employee
{
double mydata = 0;
private string _FirstName;
public string FirstName
{
get { return _FirstName; }
set { _FirstName = value ; }
}
private string _LastName;
public string LastName
{
get { return _LastName; }
set { _LastName = value; }
}
public double CalculateValue()
{
return mydata ;
}
}
2) so when i create a instance of employee class then how memory will be allocated for property, data member and member function ?
3) when this line will execute like Employee emp = new Employee(); then how memory will be allocated and also tell me memory will be allocated for which member of that class ?
4) when we call emp.FirstName ="blah" then how memory will be allocated ? and how long data will be stored in memory?
5) any memory is allocated for any interface means IStuden ?
6) we know that for any class instance memory is allocated in heap not stack but i heared that pointer is stored in heap but actual data is stored in stack. so any one can tell me with example how data is stored in heap & stack ? and also in some cases data is only stored in stack.....why ??
7) why one should create static class rather user can declare static method in non-static class and can access those method like
className.MethodName() ? so when and in what kind of scenario user has to create a static class ? is there any advantage of creating
static class ?
i know i have too many question. so i apologized but if possible please give answer in details. thanks
tbhattacharjee
|
|
|
|
|
I think there are many questions and some of them are not a simple answer, so I will try to resume.
Any code that should be loaded (like a method) will eventually use memory. I say eventually because it may not have been jitted yet, but when it is, it will use memory. But that will happen only once. It is not important if you have 1 instance or 1000 instances. The method is only once on memory.
So, for instance, only the field sizes occupy memory. An int is 4 bytes (so a class with 2 ints will occupy 8 bytes + the instance "header"). Such header is variable and I am not sure on the size... I think it is 12 bytes on 32-bit computers and 16 on 64-bit computers.
Any reference (the "pointer") is 4 bytes on 32-computers and 8 bytes on 64-bit computers.
But when you have a string field, in you class you will have 4 or 8 bytes for the reference (a null reference still uses such bytes, as zeros). Then, if you have the string filled, you will have: 4 or 8 bytes to reference a string.
Such string will have 12/16 bytes of its header + the length of the string * 2 (each character is 2 bytes) + some extra info on the string itself (I think the hashcode, for example, is always stored).
Also, virtual methods (and interfaces are included) occupy memory for their vtable... again, it is once for the class, it is not important if you have 1 instance or 1 million.
About stack and heap... in fact, any value type can be stored in the stack, and the reference can also be stored on stack... but when you already have an objet with an int, such in is not on the stack... it is already on the heap. So that means: value types and the reference themselves are kept on the "actual" location (stack or heap) while the created reference type object is always on the heap, at another location.
About the static classes, there are some scenarios.
First, a static class can never be instantiated. It looks better to create a static class than to create a normal class with a private constructor to avoid it from being instantiated.
Second, extension methods require static classes. You can't put them on non-static classes, so you may have such need.
Aside from that, there is no real difference. A static method on a normal class is as static as a static method on a static class. It is simple a matter of design choices.
|
|
|
|