|
THANKS
u clarifyed a lot of things
but for a start correct me if i'm wrong
u say be ware of this :
<br />
private void function()<br />
{<br />
class a = new class();<br />
}<br />
<br />
it is better do define it once and use it all along the app?
second :
what do u mean by
Luc Pattyn wrote: 1. are my objects larger than necessary?
and about the Dispose(), i'm learning it now to see how to implement the interface
and again THANKS
Have Fun
Never forget it
|
|
|
|
|
Hi,
half-life wrote: it is better do define it once and use it all along the app?
in programming, most objects mimic real-life objects, so their life span should correspond.
If you replace your car by a new one, that is a new object, don't try to recycle the old object.
But if your paint handler needs a Pen to draw a line, it is a similar pen each time, so why
not keep the pen handy and continue using it, as opposed to always create a new one.
half-life wrote: are my objects larger than necessary?
Data efficiency:
- store text in strings, rather than adding individual characters to a Collection.
- store image pixels in an image, not pixel objects in a Collection.
- don't use a two-dimensional array if a one-dimensional array can do the job.
etc etc.
Overall, don't make objects out of everything, items that belong together, have the same
life span, cannot exist without each other, should be part of a single object. It's things
like that that I meant here.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
|
half-life wrote: WOW, it's a big world out there
yes indeed, and the universe is still expanding.
half-life wrote: does hashtable uses a lot of resourses?
The HashTable itself is fine, storing a zillion objects in it could take a lot of memory,
when you do not really need to remember those objects (if the objects are alive anyway, then
the cost is basically just a reference to the object; when the object is not referenced anywhere
else, keeping it in a HashTable keeps it alive, hence costs the entire memory footprint of
the object).
It is a common memory leak: create a class, add a static collection to it that remembers
all instances of that class, have some debug code listing all those instances, etc, but
ignoring that the collection keeps growing while it remembers all these instances, even
if they are no longer alive outside the class.
half-life wrote: for every Question there is an Answer
not quite. In general, some questions have no answer, some have one, some have many.
On CodeProject forums, most questions have many replies, not all of them are actual answers.
half-life wrote: creating hashtables insted of frequentlly using the foreac
These are different things. HashTables are handy to remember associations between a number
of keys and an equal number of values. foreach is a way to loop over all elements of a
collection.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
|
Yeah, that's one (or two) of the things he meant.
That instance has local scope, so when the function exits it will be garbage collected... eventually.
If that doesn't happen in a timely manner, and you call this function frequently, you could be wasting memory with a bunch of these instances.
So, if the class is Disposable, either call Dispose before exitting the function, or use the using statement (not the same as the using directive).
Alternatively, you could add a field (perhaps static ) to your class that will hold onto the instance for a much longer time, this technique has the added benefit of reducing the overhead you incur with instantiating and disposing the object repeatedly.
|
|
|
|
|
THANKS
SO, a singleton class would also be good for THOSE kind of thins ?
Have Fun
Never forget it
|
|
|
|
|
Memory manufacturers don't like singletons. They don't want you to work for hours on a class
that will only be instantiated once.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
SO i'll make them angry,
Have Fun
Never forget it
|
|
|
|
|
They like Disposable items though.
|
|
|
|
|
How do I share my C# source code of project with you. My program's subject is about simulation and
fuzzy logic . I'm beginner and I want to know your ideas and opinions about it. I use C#.NET 2003.
|
|
|
|
|
Write an article and post it on codeproject
|
|
|
|
|
Write a well formed article about it and place it on code project. What I mean about well formed is, don't just throw a ton of code in an article and just submit it. Discuss certain aspects of the code you find interesting or challenging in the form of a paragraph or two ( 4-6 sentences each ).
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
In a slight bending of the Hole Good Code Rules, in favour of simplicity, I am implementing a Grouping attribute (type string) on a UI class of mine, the ExportLine. It can have one of three constant values, or the name of a grouping field. What is the best way to implement the contant values? I'm thinking static properties on my ExportLine. Given what I'm doing is not really good anyway, is the properties approach a good one?
|
|
|
|
|
I'm not quite sure I follow you, but maybe readonly fields would be better?
|
|
|
|
|
I'm not sure if better, but definitely an option worth comparing to mine. A get only property, and a read only field are pretty similar if the are only read inside their class.
|
|
|
|
|
I doubt you could argue that the property is better either. Unless you want it to be virtual ?
A readonly property that could easily be replaced by a readonly field may wind up in the "coding horrors" forum.
|
|
|
|
|
I've moved the static properties to a class specifically to hold them. It has no code, so I think the difference is moot now.
|
|
|
|
|
HI,
i've got a problem.
i'm canginng the computer Resolution so it fit my APP (Like games do at when they start)
and rechanging back to the old Resolution when the APP closes.
So far So Good, but i don't know how to save the icon's layout
when i change the Resolution back, i'd like to save the layout so the user gets the screen he had
before working with APP
THANKS
Have Fun
Never forget it
|
|
|
|
|
|
If clicking the button submits a form (vs. executing some JavaScript), you can use a WebResourceProvider [^] to do your bidding.
/ravi
|
|
|
|
|
Hi
I want to access files which are on a network share in another server.
When I try to access (manually, not through C#) the other server I get the window of username and password and I can access the files.
I want through C# to read the files which are in this share and to specify within C# the username and password for accessing the share.
Any ideas ?
Clint
|
|
|
|
|
|
hi ,
i am a newbie to C# programmin , reading it from a book(C# Software Solutions. Foundations of Software Design author John Lewis). the other day i was trying to solve a question given in the book wherein , i have to create a program that reads an arbitrary number of integers (in range of 0-50 inclusive) and counts how many occurences of each are entered, once all the inputs are processed , the output should print the values (with number of occurences) that were entered one or more times.
finally when the program is working , i have to try the same in the range of (-25 to 25
can anyone help me with the coding of this program..
thanks
|
|
|
|
|
harrysc74 wrote: can anyone help me with the coding of this program..
What part of the program are you having trouble with? What code have you written so far?
No one is going to do your homework and write the program for you. If you want help with a specific problem, post your code and someone might be able to asist.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|