Click here to Skip to main content
12,697,699 members (25,608 online)

Comments by Paulo Zemek (Top 75 by date)

Paulo Zemek 5-Jan-16 20:11pm View
Reason for my vote of 3 \n The class works and I agree it can be useful for a very specific scenario. Yet, having that class only to use that very specific scenario seems overkill to me. Also, the presentation makes it looks much more generic purpose than it should, and I am afraid that can become a bad practice.
Paulo Zemek 30-Sep-15 14:50pm View
That's the thing... HashTables are not accessible by index. They are enumerable, so you can implement forward only navigation with ease, yet you can't guarantee an order.

Yet, what exactly are you storing in your HashTables?
Notice that you can actually have a List of HashTables. So, the list would represent the records, where each HashTable will represent a single record (having the column name as the key, for example). Having a single HashTable to store multiple records, where each record have multiple columns seems completely wrong.
Paulo Zemek 29-Sep-15 19:12pm View
A navigation using hashtables? Are you sure you want to do that?
A hashtable is a way of indexing data. The purpose of the hashtable is not to navigate records (be it one by one, by page or anything similar). The purpose is to find an item as fast as possible by its key.

For example, when you use htData(...) if htData is a hashtable, it will find the value for the provided parameter (the key) as fast as possible. It actually doesn't matter if the pair (key/value) is located as first item or as last item.
Paulo Zemek 15-Jul-15 21:35pm View
He shows a foreach over s... and then it seems the foreach is over evnts... so I got confused. Anyways, I am looking at your solution now.
Paulo Zemek 15-Jul-15 20:29pm View
I don't see you checking for null anywhere.
If ViewBag is null, you will have that exception.
If evnts is null, you will have that exception.
I don't know your actual collection, so if an evnt inside a valid evnts is null, then you will have that exception.
If none of those was supposed to be null, it doesn't mean they will never be null. It can mean that somewhere else has a bug and a null is arriving to this piece of code.
Paulo Zemek 14-Feb-15 17:15pm View
Unfortunately, I don't know any site or community to recommend.
Paulo Zemek 12-Dec-14 20:32pm View
Normally you use pointer to objects...
For some reason, you want to use a input parameter as output (COM, for example, uses HRESULT to indicate success/error, so any result is a pointer to a variable that will hold the real result). When that variable is already a pointer, you end-up with a pointer to a pointer.

More than that is rarely justified but can happen (for valid or invalid reasons). For example, imagine that the first member of a linked list is a pointer to the next item. Being the first item, someone may prefer to access the 5th item by dereferencing a pointer to a pointer to a pointer to a pointer to a pointer instead of using: linkedListFirst->next->next->next->next or some method like linkedListFirst->getItemByIndex(4) // 0 based index.
Paulo Zemek 18-Sep-14 12:59pm View
I really believe the bug is in your property getter.
Also, are you sure you are notifying the right property name? Maybe a single letter can be the cause of your bug.
Paulo Zemek 19-Aug-14 12:54pm View
Well, I think that I was clear. I said that it was the MainViewModel constructor, I said that he created a local variable that was not used and I said that I believe he wanted to do the MouseDown +=... call, explaining that he didn't do it, that he only created a delegate... so I understand that the MouseDown += ... was a correct, yet I was using it exactly to talk about the correct one.
In any case I want to know if the original poster will say something else.
Paulo Zemek 19-Aug-14 8:21am View
I am talking about the ViewModel constructor, not the form. The ViewModel is the one with problems.
MouseButtonEventHandler mouseButton = MouseClickHandler;
mouseButton is a local variable, and it is never assigned to anyone.
Paulo Zemek 19-Aug-14 8:20am View
I am talking about the ViewModel. This line:
MouseButtonEventHandler mouseButton = MouseClickHandler;
mouseButton is a local variable.
Paulo Zemek 18-Aug-14 17:00pm View
I think that you are really lost... but I will try to explain what I see.
In the MainViewModel constructor you create a mouseButton local variable that points to the MouseClickHandler. Such mouseButton variable is never used and will be collected.
I am pretty sure that you wanted to do something like the MouseDown += MouseClickHandler, but the only thing you did was to create a delegate for that method and let it die.
Then there's the real problem: The ViewModel can't know about the existence of the MouseDown event... it is the View that should know about it.
If you were using the Click event we could create a Command to do the job, but if you really want the MouseDown event, there's no perfect solution, the View will still need to implement that event, even if its only job is to call a method of the ViewModel.
Paulo Zemek 8-Aug-14 19:41pm View
I think he wants to save an entire dictionary as a single field in the database... like a string or int.
Paulo Zemek 17-Jun-14 17:31pm View
Note that actually there are game-wide information, mission specific information or something-else specific information.

For example, during a mission, some data may be stored regarding the character and others that he talked to or about items he had touched. As soon as the mission ends, all that info may be lost.

Booleans? Well... you can use a hashset of strings (not the best, but only to exemplify) and store all the data that may be of "interest" to the mission. Things like:
"TouchedTheMagicCat", "KilledADragon", "KilledTheDragon"... or anything else. Note that all of those could be boolean variables inside a single class, but by using a hashset you never need to have a class with all the possibilities (and so, if the missions may be loaded from xml files, the "needed items" may be searched by names instead of counting on an existing field).

Then, we return to the idea: Each npc (or room, if each action is by room) may look for specific traits in the current character mission... or in the current character itself (like the character level). And anything can be stored if it is important for the game (number of kills the character did, number of times the character died and was revived... even the number of saves done in the game...).
Paulo Zemek 17-Jun-14 16:52pm View
In fact, it is important to note that the state is not in the player character or in the room/npc (except if it is a single player game). It is in the combination of both.
In the database, it would look like:
PauloZemek/FirstItemSeller (the key) -> anything else. The information needed by the game.
So, another character will have its own key (SomeOtherUser/FirstItemSeller)... and other sellers/persons that you talk on the game will also have their own.
Paulo Zemek 17-Jun-14 16:50pm View
Think differently.
When a character talks to someone (in this case, enters the room and there's a person interested in talking to you).
That person may be programmed like:
Check when it last talked to you (this will look into the database to see if there's a registry binding that player character to this npc character).
If there is not:
Hi. Are you new here?

If there is. Then, it looks:
Was that character in a mission last time it was here?
Is it in a mission now?
Is it the same?

Those conditions may yield results like:
Do you need any help with your current mission?
How did your last mission end?
Hey... I see that you are in a new mission. Needing new items?

So, that character has many "conversation paths". It only needs to look for information about the currect character talking to him, and it can use the database to have "memory".
Paulo Zemek 20-Feb-14 14:05pm View
Logically speaking, a thread waiting is paused (I understand that its state is not named Paused, but what I mean is that such thread can process other things)...
And apparently the objclsSMS_incoming is running on the same thread... so, as the thread is waiting, it will not invoke such method... so the action is always timing out, then such message is processed and sets the event.
Paulo Zemek 20-Feb-14 13:22pm View
The AutoResetEvent pauses the current thread.
The objclsSMS_incoming is probably running on the same thread and so, it is not going to be invoked until the test_Click returns.

In fact your problem is related to how the windows messages are processed. Any event (like click) is a windows message and it must finish its work before processing another message. So, you are waiting for the sms_incoming while the sms_incoming will wait until this method returns.
Paulo Zemek 17-Feb-14 6:57am View
You should compare the result from EndSend with the length of the data used in BeginSend().
For example, if the BeginSend() used a buffer with 100 bytes and EndSend() return 30, this means you must send the remaining 70 bytes. That is, you should call BeginSend again, giving the same buffer, but instead of 0, byteData.Length it will be 30, byteData.Length-30.
If this second send ends-up sending 10 bytes, you will have sent a total of 40 bytes, so the next send should send the bytes starting from 40, with a count of byteData.Length-40.
Paulo Zemek 16-Feb-14 14:11pm View
I think that your biggest problem is this line:

if (ar == currentAsynchResult)

Actually, the ar is what's important. There's no real "currentAsyncResult" as if you send data to two or more clients, you actually have 2 or more IAsyncResults.

So, your code should be capable of dealing with more clients. And it is no surprise that the send size is always the same... if you are sending the same data to all clients, the size will be equal. You could actually create the message and get its bytes outside of the loop.

And maybe you should revise your method names, as the OnBroadcast is not a broadcast. The method that does the broadcast is the one called SendToAll. The OnBroadcast is actually the method that will be invoked when a message arrive a client (it is not important which, and even the order doesn't need to be the same as the order of the send calls).
Paulo Zemek 16-Feb-14 7:59am View
Are you sure that it returns that?
When I look:

I see that EndSend() receives an IAsyncResult, but it returns an int.
Also, if you try to build an string with the wrong number of bytes you can receive an exception.

And you don't need to use encoding.GetByteCount()... simply use the EndSend() result to know how many bytes it sent.
Paulo Zemek 27-Dec-13 0:37am View
Thanks for accepting the answer. I did correct the name, it is not "TcpDelay", but "NoDelay" which, in fact, works in the inverse sense (so, a NoDelay of false = TcpDelay as I explained it).

In either case, I hope you are able to figure the problem out, be it with the Tcp/No Delay or because my article is useful.

Good luck with your game!
Paulo Zemek 30-Nov-13 17:11pm View
Reason for my vote of 1 \n First, I agree with abdurahman ibn hattab. The original code seems easier to understand than your new solution.

But I think the problem with this article/tip is related to many small problems.
First, you say that switch is code smells and I usually agree. But then you start with a "key/value" table without explaining how this relates to dictionaries and, worst, you affirm that its key has a variable number of parts when, in fact, it has a fixed key that should allow null/empty values.
Second, there's no explanation at all of the KeyParts.cs. In fact, I think such class is not needed. Any list could do the job. And I should say that the problem is even bigger, as the PutAllInTheSameBasket is always zero. So, why use a dictionary? The only benefit of a dictionary over a list is how it index its values, but by having all values with the same hashcode, you are using a dictionary as a list, but you are using more memory than by using a list.
Third, independently of your bad use of a dictionary, the original code used "StartsWith". I am not trying to say if that's right or not, but your actual implementation compares with equality. That is: StartsWith("A") will accept "AAA". Your implementation will not, as "AAA" is not "A". If such "StartsWith" was an error, then it should be explained.

So, sorry, but your "solution" to a problem seems to be a bigger problem.
Paulo Zemek 17-Oct-13 23:51pm View
Reason for my vote of 5 \n I am revoting 5. As a tip/trick I think it really a good presentation on how you evolved the pattern. I hope you are not mad at me about the previous vote.
Paulo Zemek 22-Sep-13 21:25pm View
I am not sure about which objects are global and which are local. For example, if your Main.detailQueue is shared between the different tasks, then locks should be used (after all, tasks are different threads, so you should not update a shared object by multiple threads without lock).
Paulo Zemek 22-Sep-13 10:58am View
I can't compile such code as it references methods that aren't present here.
But in the title you say that you have an AggregateException. Can't you see the inner exceptions and their stack-traces? Maybe by seeing the stacktrace you will go directly to the line that's causing the exception.
If you are able to cause the bug while debugging, you may activate exceptions to be shown when thrown and not only when they aren't caught.
Paulo Zemek 21-Sep-13 22:39pm View
Application.DoEvents does not wait at all. Considering it worked from another thread, that only means you will consume 100% of one CPU while the ReadyState is not complete. So, I gave a solution (which I consider a bad solution) that keeps the idea of using another thread instead of using the correct event. In such case, you can either ignore DoEvents completely (so, remove that line, but use the same while to keep waiting) or, if you don't want to consume lot of CPU waiting but still wants something responsive, you use a Thread.Sleep of at least 1 millisecond (which, in practice, will probably be something near 15 milliseconds as that's how windows usually works).

About the WebControl.Invoke... what I can say is this: If you don't do cross-thread calls, you must "ask" the main thread to execute some code... that's done with Control.Invoke (so, Window.Invoke, button.Invoke or similar). But I can't simply tell you how to write it in VB.NET because I am not really used to VB.NET... I can write the code in C# with ease.

Yet, I don't understand the purpose of this, as the best solution will be to use the PageLoaded/Completed event or similar.
Paulo Zemek 21-Sep-13 18:54pm View
So, in such particular case, your problem is still the checkforillegalcrossthreadcalls. In fact, such test should be kept, but you should send a message to the control in the while. I think you are using WindowsForms and I don't use it actually, but I believe you could use a WebControl.Invoke(TheMethodThatDoesTheStatusValidation) instead of checking the state directly...

But if you really want the simplest solution, replace the Application.DoEvents (which is completely incorrect) by a Thread.Sleep(10) for example. So, at each 10 milliseconds you check the state again.
Paulo Zemek 20-Sep-13 13:56pm View
Reason for my vote of 5 \n Simple, yet very interesting and useful.
Paulo Zemek 14-Aug-13 17:36pm View
Reason for my vote of 5 \n Great tip.
Paulo Zemek 21-May-13 12:11pm View
I can see the code is in portuguese, so I can have a few assumptions: CodCid means City Code... so it should be an int. PES_DATA_NASC means BirthDate, so it should be a Date, which needs at minimum to have 'yyyy-MM-dd' format, but it is added without quotes and will probably use the dd-MM-yy / dd-MM-yyyy that are common in Brazil (I am not sure if the author uses Brazilian portuguese and I don't know the format in Portugal, but there are great chances that the format is wrong).

But I strongly recommend the insert SQL to be like this:

And then use parameters to fill each one of the values. That will help database drivers to reutilize commands and indexes, will solve all your data-type conversions and will not be vulnerable to SQL injections.
Paulo Zemek 18-May-13 21:41pm View
Usually it is better to cache a value instead of reading the file every time. But to cache the value, it is important to know if such value is acessed from a single thread or from many threads.
Also, I see a sr.Dispose() when you are already using a using clause, so you don't need to dispose (as the using clause creates a dispose at the end).
Paulo Zemek 30-Mar-13 11:46am View
The problem is not the value (1, 4096 or any other... the problem is that you are using the buffer length, not the amount of data really transferred).
Also, you never really made a question.
Paulo Zemek 29-Mar-13 17:16pm View
I think it is corrected now... and with a validation at the beginning to make it better.
Paulo Zemek 28-Mar-13 17:42pm View
It was an error really... it should be double current=numbers[count-1]... but I said I didn't test.
Paulo Zemek 26-Mar-13 16:29pm View
Well... so, if there is no one else reading the file... I simple don't know... the code seems fine to me.
Paulo Zemek 26-Mar-13 15:44pm View
Are you accessing the file from many processes in the same computer? Or are you acessing the file from the network?
Paulo Zemek 5-Feb-13 10:23am View
Reason for my vote of 3 \n Even if the code works, you are destroying the purpose of the dictionary doing it. The Dictionary is considered almost O(1) because it is indexed, but with your method you will do a normal scan... in fact, if there are no valid matches, it will be an O(N) operation.
Paulo Zemek 24-Sep-12 8:52am View
Exactly... in fact, the stride is how many bytes a line utilises, and it is not necessarely the Width * bytes per pixel because of memory alignement. Sometimes it will be a multiple of 8 even when the image width is not a multiple of height (for example, the image is 77 pixels, but the Stride is for an image of 80 pixels). So, it is important to use the stride to find the beginning of a line (line index * stride).
Paulo Zemek 5-Jul-12 11:19am View
Reason for my vote of 1
It is something simple... with errors.
In the method, it should get the handler first in a local variable, check if that variable is null and only call the handler (using the variable) if it is not null.
And the method (OnPriceChange) should not receive the object sender. It already has the this. It should also be procted virtual or private if the class is sealed.

So... too many errors for a simple thing.
Paulo Zemek 19-May-12 14:59pm View
Probaly you did everything right and those 40mb will be reutilised for new allocations. There is no problem.
Paulo Zemek 18-Apr-12 20:06pm View
Reason for my vote of 5
I will not adopt it personally, but your arguments really convinced me of the usability.
Paulo Zemek 3-Apr-12 9:23am View
I am not sure about what you tried to ask.
If you are concerned about the class name used as the field or property name, that is usually a more conceptual problem than a real one (if the name is short and already tells what it should tell, then there is no reason to change it only to avoid a property having a name that equals to a a class name).

But if you are asking why use a property instead of a field, it is related to run-time behavior.
Imagine that today emp is assigned during creation to a field. But, in the future, you don't initialize it immediately. If it is a property, acessing Emp will execute the code in the property, which will check for the null field and initialize it if needed.
You can change the field by a property of the same name, but already compiled code that depends in a library, for example, will cease to work (as they will expect a property, not a field). If it was always a property, even if it was a simple get/set, if you change how the get works, all code that depends on that property will continue to run, as they depend on the existence of the get_Emp method (created when you declare the property getter).
Also, if you follow naming conventions, public members always start with a capital letter (and fields should never be public except for rare cases, like the ones used when declaring Dependency Properties which are also read-only).
Paulo Zemek 17-Mar-12 21:39pm View
I didn't said they were the only options... but I said to look at them both... depending on the situation they already solve the problem... or depending on the situation they are a good start (after all, I always see the inheritance of a class if that class is not exactly what I want).
Paulo Zemek 23-Feb-12 15:18pm View
Doesn't initializing the field with a call to a static method solves the problem? For example, even for .Net 2.0, you could declare something like: static List<int> _list = _InitializeList(); Then, you could put all the code you need to initialize list there. The difference if compared to a normal static constructor is in the order of the initializations, as they are not forced.
Paulo Zemek 26-Jan-12 11:02am View
No problem.
Paulo Zemek 26-Jan-12 9:59am View
I think this last version is almost OK. In fact, if you know the type at compile-time, you don't need the method at all. Why use: CachedNew<Something>() when I can do: new Something(); ? But, considering it received a Type as a parameter, then it is almost OK. If it is static, then it must deal with concurrency problems (lock or some kind of ReaderWriterLock).
Paulo Zemek 25-Jan-12 15:55pm View
I don't see any problem with statics. If it is for performance, statics perform better (even Code-Analisys tells you to use static if you don't use the "this" directly or indirectly).
Also, you can always create another, non-static class, that implements an interface and redirects to the static one.
Paulo Zemek 26-Dec-11 18:42pm View
In my case it was a recently installed computer... it has a real hardware problem, but I only noticed it in my application.
I don't even know its real cause... but a new computer was brought and solved everything.
Paulo Zemek 26-Dec-11 18:40pm View
This is an old question... but the problem was a hardware one that appeared very often in my code... already solved.
Paulo Zemek 2-Dec-11 12:08pm View
It is OK now.
Paulo Zemek 2-Dec-11 11:33am View
Sorry, but you are wrong.

If the locks are always in the same order there is no chance of dead-lock... and that may be needed.
Usually that happens on different levels of locking. Imagine that you have a thread-safe list. Add and Remove do a lock.
But, at another place, you want to call Contains before and, if contains is false, add an item. The thread-safe list will be thread-safe at each add or at each contains... but between contains and Add, you may have another thread adding an item. So you will use another (external) lock.

In fact, you will always have:
External Lock - Internal lock (when using the Contains->Add).
Or you will have only internal locks. Surely having only external locks will work, but there are reasons to have two locks that way.

And I think your code was not rightly tested.
Create a situation where lock1 will work and lock2 will not. It will keep locking lock1 and not lock2... make it timeout... and then try to lock the lock1 by another thread. You will not be able to do it, as you lost a lot of locks.
Paulo Zemek 1-Dec-11 8:50am View
But you are using a thread when doing BeginInvoke, even if you don't see it.
What happens is:
The page ended, and the server code does not affect the client anymore. You must put a client code (a javascript code) to run after sometime.
Paulo Zemek 1-Dec-11 8:41am View
Why do you want to use BeginInvoke?
Why not simple call the delegate directly?
Your problem is:
Thread A:
Page_Load (for example) starts a second thread with your delegate.
Page_Load continues while the other thread continues.
Page_Load finishes, the response is sent... and the other thread continues.
Doing anything on the other thread now is useless.

So... do it synchronously, call the delegate normally, not as BeginInvoke.
Paulo Zemek 1-Dec-11 8:30am View
You can't use parallel code to do that... well... at least not parallel code that can end after the actual ASP.Net method.
So, if you are in Page_Load, you can generate any async event, as long as the Page_Load waits for the end of such parallel delegate. (and if both affect the response, then you will need locks).
But considering that web-servers usually already use all their cpus when there are enough clients, I think you should not use BeginInvoke. Simple invoke the delegate normally.
Paulo Zemek 25-Nov-11 7:36am View
I didn't understand what you are really asking.
But you are starting two threads and you are only joining to the last one. And why use a thread to join it? Call the method directly... I really can't help because I can't understand what you are really trying to do.
Paulo Zemek 25-Nov-11 7:34am View
How a ReaderWriterLock will make values from 0 to 99 be ordered?
ReaderWriterLock is for protected a resource that is not thread-safe (so, many readers at once or only a single writer). But it does not order the threads... if one thread is faster than the other for some reason, they will be unordered. And Console is already thread-safe.
Paulo Zemek 24-Nov-11 7:12am View
Right. In that case, it will be unboxing the value, which is fast. The problem is boxing (which allocates memory) but this happens only when storing a value type as object (like when putting it into the array).
Paulo Zemek 23-Nov-11 16:46pm View
I just corrected that and than saw your comment... it is Action<object>
Paulo Zemek 17-Nov-11 11:18am View
Reason for my vote of 5
I am giving you a five because I didn't knew the BooleanToVisibilityConverter... also I think it is strange that true is hidden (as the name is visibility) and I liked that you allow all the possibilities for the boolean. I think that if the value is null you may use the other value between hidden or collapsed, so the user may use true, false or null.
Paulo Zemek 17-Nov-11 8:09am View
Reason for my vote of 5
There are things to improve... but this is the smallest implementation I've found that is prepared for 8-bit, 24-bit and 32-bit.
Paulo Zemek 9-Nov-11 8:26am View
Well... in that case I agree and disagree. LINQ will be better... but by the fact you don't need to create a new list. Creating one... well... I can say that the best option is to iterate the reverse way and delete the invalid items to save memory.
Paulo Zemek 9-Nov-11 7:45am View
Reason for my vote of 2
I already posted... but the reason is: You still need a foreach to iterate through students. You are giving an incomplate example and are replacing the if, not the foreach.
Paulo Zemek 9-Nov-11 7:44am View
Well... you may replace the if with linq... but you still need the foreach
After all, how do you iterate through the "bestStudents"? I will do a foreach.
Paulo Zemek 2-Nov-11 10:09am View
Paulo Zemek 1-Nov-11 15:42pm View
If you want, take a look at those articles (that I wrote):

One of them explains why not even the using keyword is safe (and the .Net framework itself uses it) and the other explains how to create a "safer" Abort. Either way... independent on the complexity of the animations, after each Thread.Sleep it is possible to check the boolean value and exit naturally.
Paulo Zemek 1-Nov-11 15:33pm View
Thread.BeginCriticalRegion, as far as I know, only affect protected environments (like .Net code running inside SQL Server).
You can do the test yourself. Create a thread. Call BeginCriticalRegion and then enter an infinite loop.
Then another thread call abort. And see what happens... the thread is aborted.

To avoid the abort the code should run inside a finally block... but that can cause other problems and we must remember that we call code that usually is not prepared to deal with aborts. As I said, if a thread is used, the best is something like this:
<pre lang="cs">
Thread.Sleep(time) or manualResetEvent.WaitOne(with timeout);
// in the case of timeout, exit immediatelly.

And to cancel that thread set stopped to true. It should be volatitle to avoid problems.


But, in my opinion, the best solution is to use the appropriate timer (Windows Form timer or DispatcherTimer) so you don't need to call Invoke. Of course, only a single instance (if the application is multi-threaded, then store it in a [ThreadStatic] static variable... if it is not, a simple static variable will work).
Paulo Zemek 1-Nov-11 14:26pm View
No... I am not confusing. I even wrote an articles on why "using" keyword is not abort safe. But the fact is, Abort may happen at any IL instruction. For example, between the allocation of an unsafe object and just before storing its value into a field, so even the finalizer will not solve the problem.
It is much simpler (if a thread is really used) to have a bool flag. So, when finishing, set the flag (ended) to true, and then also signal the ManualResetEvent. So the thread will be terminated at the right point.
Paulo Zemek 1-Nov-11 13:12pm View
If using a lot of timers is bad, using a lot of threads is even worse. Using abort is even a worse practice.
Paulo Zemek 18-Oct-11 7:49am View
Class static members are all loaded when the class is first referenced.
Now, imagine that your class has 10 properties (not a single one). If you want to load those properties only when they are first referenced, then Lazy is good.
If you create an object (so, not a static class) and it has a property that's really slow to initialize, but rarely used, then Lazy is good.

But, for a single property, inside a static class, it is useless.
Paulo Zemek 5-Sep-11 21:24pm View
I think the start is wrong... we can pass types as parameters.
A method like this:
<pre lang="cs">
void ShowName(Type type)

Can be called as:
<pre lang="cs">

Or as this:
<pre lang="cs">

If you are trying to say that we can't pass enum types as type parameters, I will partially agree, as we can't use where T: enum. But, you say that generic methods solve the problem, so that's not the case.

The only advantage (if that's really to be considered one) about using generic methods to pass types is that null or open generic types (like List<> without specifying a data type) will never be received. But doing the necessary ifs are probably faster than counting with the generation of the method.
Paulo Zemek 1-Aug-11 15:00pm View
I agree that var is not a problem, by another reason:
In one line it can be: var data = GetData().
Of what type is data? I don't know.
But at another place, I can simple see data.DoSomething(). I don't have the declaration there to look for the type, so what's data.DoSomething???

For me, replacing var by the real type will only solve my problem if I am near the declaration of "data". But having a more meaningful name will solve the problem everywhere I see the new name for "data". So, better variable names are better.

And, if we think about lazy programmers... well, they do a lot of "bad practices", be it with var or not.
Paulo Zemek 1-Apr-11 13:30pm View
I am talking about CPU cache, not about the Cache object.
Paulo Zemek 11-Feb-11 13:46pm View
I was confusing the posters... but we don't say the same.
You say it is not possible to overlap. They can. One thread can be sending, and another thread can be reading on the same socket. What can't happen is two threads reading or writing at the same time (in fact, in .Net, I can't even write from many threads, even if I use a lock, so I send everything to a single thread, that serializes writes).
Paulo Zemek 18-Jan-11 14:40pm View
Now I understood the "post a comment instead of a new answer".
In fact, I have many purposes for this, but my biggest one is the session/viewstate manager. All view-state "buffers" (items in it, after serialization) are stored in memory, up to a number X of bytes. This is to make things faster. If more buffers than the "reserved memory" are needed, then they are saved to disk.

So, what I want is:
I have a computer with 16gb. I allow up to 5gb to be kept in memory. More than that is stored in disk (considering that old [less used] buffers are written first).
But, in fact, what I have is:
Even if only 100mb are allocated, the memory start to get written to the pagefile. So, the more buffers I keep in memory (to avoid disk accesses) the more disk accesses I have, as the pagefile get used more and more. And, even worst, the pagefile is used in a "random" order considering my needs, when it still has more than 10gb of memory free.

So, disabling the pagefile solves the problem. But, then, if for some reason another process someday needs that extra-memory, I will not have it.

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 1 Jan 1900
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid