about to understand resources

T

Tony Johansson

Hi!

It's easy to understand memory but I find it harder to really understand
resources.
Some of you has mentioned resources such as file object, network sockests
and things like that.

If we for example take the file object resource does this mean that there
exist a maximum number of file object that can exist in an application.

If we for example take the Pen object resource does this mean that there
exist a maximum number of Pen object that can exist in an application.

If we for example take the Brush object resource does this mean that there
exist a maximum number of Brush object that can exist in an application.

If we for example take the Network sockets resource does this mean that
there exist a maximum number of Network sockets object that can exist in an
application.

This was just an example of a coupe of classes that implements the
IDisposable.

Should I understand it in that way that my example describe ?

//Tony
 
P

Peter Duniho

Tony said:
Hi!

It's easy to understand memory but I find it harder to really understand
resources.

Simply, a "resource" is anything that is of finite supply on the computer.
Some of you has mentioned resources such as file object, network sockests
and things like that.

If we for example take the file object resource does this mean that there
exist a maximum number of file object that can exist in an application.

Yes. An application can open only a finite number of files at a time,
and this number is limited by factors other than just available memory.
If we for example take the Pen object resource does this mean that there
exist a maximum number of Pen object that can exist in an application.

Yes. Same thing.
If we for example take the Brush object resource does this mean that there
exist a maximum number of Brush object that can exist in an application.

Yes. Same thing.
If we for example take the Network sockets resource does this mean that
there exist a maximum number of Network sockets object that can exist in an
application.

Yes. Same thing.
This was just an example of a coupe of classes that implements the
IDisposable.

Should I understand it in that way that my example describe ?

Yes. That seems fine.

If you want a greater detail of what's going on, you can read about the
unmanaged API. In Windows, below .NET, is the original unmanaged API,
which continues to evolve even as .NET adds its own layer of API to the
operating system.

In the unmanaged API, a "handle" is the basic object reference, and
different kinds of handles have to be allocated differently. Pens and
brushes, for example, are represented by GDI handles.

There are a variety of limits involved, so there's not a simple way to
describe what the actual limit is. And in reality, the current limits
on handles are quite high; it's much less common for an application to
reach an allocation failure due to insufficient handle resources. But
it could happen, and it's _much_ more likely to happen if you don't
dispose your IDisposable objects.

Mark Russinovich writes about these topics regularly. So if you're
curious, you might want to start with his blog:
http://blogs.technet.com/markrussinovich/

Oddly enough, just last week he posted an article on the topic, and
included a bunch of links to previous articles on the topic:
http://blogs.technet.com/markrussinovich/archive/2010/03/31/3322423.aspx

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top