Last post Sep 07, 2013 08:53 PM by Paul Linton
Sep 06, 2013 04:31 AM|FruitBatInShades|LINK
I'm planning on extracting some class methods into a static library. The code all works fine but I'm wondering how the runtime handles thousands of request to a static method. I've done a quick test creating 5000 threads all calling the same method and it
Does .net cache the requests, create another instance or am I just being lucky so far?
Sep 06, 2013 06:41 AM|AidyF|LINK
The static method exists on the type rather than a type instance so the only difference is that it doesn't need an instance of the object to call the method. The performance of the method itself isn't really any different, but the fact that you don't need
to create an object to call the method can be an advantage. If you really want to get down to the nuts and bolts, this might make interesting reading
For your general purposes though, you shouldn't really see any negative effects from what you're doing, and you could get a bonus from not having to create objects just to call your methods, however if you already create the objects for other reasons then
that point is moot.
Sep 07, 2013 08:53 PM|Paul Linton|LINK
What do you mean by
"Does .net cache the requests"
What requests? What you seem to be describing is a method call. What sort of request do you think might be happening? What code is creating this request? What do the methods do?
You say that you create 5000 threads all calling the same method ... so are you calling within the same process or sending a request to some remote process?
If you are just calling a method then there is no request. Therefore there is no caching of the non-existent request.
Are you being lucky? No idea, unless you show the code and we can see how you are handling the locking of the data structures that are being accessed.