| View previous topic :: View next topic |
| Author |
Message |
vfunc@talktalk.net Guest
|
Posted: Mon Jan 30, 2006 11:00 pm Post subject: restricting memory |
|
|
Is it possible to restrict the memory available to a class where say
for example it contains an array of elements of varying size or
variable size list or a mix of these? Is the normal way to do this, to
record the useage as new elements are declared and then compare this
useage to an upper limit? |
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Mon Jan 30, 2006 11:00 pm Post subject: Re: restricting memory |
|
|
vfunc (AT) talktalk (DOT) net wrote:
| Quote: | Is it possible to restrict the memory available to a class where say
|
What do you mean by "restrict"? Prohibit any allocation of more than some
specific number of instances of that class? Make the allocations be taken
in some particular area of the memory? What?
| Quote: | for example it contains an array of elements of varying size or
variable size list or a mix of these? Is the normal way to do this, to
record the useage as new elements are declared and then compare this
useage to an upper limit?
|
The normal way is to let the system tell you when you've run out of memory
by catching 'std::bad_alloc' exception.
V
--
Please remove capital As from my address when replying by mail |
|
| Back to top |
|
 |
vfunc@talktalk.net Guest
|
Posted: Tue Jan 31, 2006 1:00 am Post subject: Re: restricting memory |
|
|
Instances possibly but otherwise no, that is not what I am asking.
Restrict the allocation to a specific size be that in one class or for
all instances of a particular class within a module (not globally) e.g.
say I want a class to use no more than 1Mb of memory. |
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Jan 31, 2006 6:00 am Post subject: Re: restricting memory |
|
|
vfunc (AT) talktalk (DOT) net wrote:
| Quote: | Instances possibly but otherwise no, that is not what I am asking.
Restrict the allocation to a specific size be that in one class or for
all instances of a particular class within a module (not globally)
e.g. say I want a class to use no more than 1Mb of memory.
|
I guess I don't understand the problem yet. If you need to restrict
the amount of memory spent on any particular class, including any
dynamic memory objects allocate, you'll need to have some kind of
measurement built into every object. That measurement would account
for the dynamic memory as well as the memory the object itself takes
(sizeof(object)). You're going to need some overhead accounting as
well, but that's implementation-specific.
Now, if you do not care to account for the dynamic memory the objects
themselves can allocate, then you just count instances because the
memory they occupy will be (N * sizeof(thatclass)). IOW, take your
1 Mb and divide it by (sizeof(thatclass)) and you get your number of
instances allowed to be created...
V
--
Please remove capital As from my address when replying by mail |
|
| Back to top |
|
 |
Ben Pope Guest
|
Posted: Tue Jan 31, 2006 10:00 am Post subject: Re: restricting memory |
|
|
vfunc (AT) talktalk (DOT) net wrote:
| Quote: | Instances possibly but otherwise no, that is not what I am asking.
|
Please quote what you are referring to.
| Quote: | Restrict the allocation to a specific size be that in one class or for
|
Do you mean the memory that one instance of the class allocates?
| Quote: | all instances of a particular class within a module (not globally) e.g.
say I want a class to use no more than 1Mb of memory.
|
I'm not sure what you mean by "within a module (not glabally)", your
example does help.
A Class doesn't use memory. An instance of the class does.
If you want to limit the amount of memory one instance can "use", then
Victor has the solution. If you want to have a total limit for all
instances, then you will require some static data in that class, keeping
track of the memory in all instances.
Ben Pope
--
I'm not just a number. To many, I'm known as a string... |
|
| Back to top |
|
 |
vfunc@talktalk.net Guest
|
Posted: Tue Jan 31, 2006 11:00 am Post subject: Re: restricting memory |
|
|
| Thanks, a counter is the way. |
|
| Back to top |
|
 |
vfunc@talktalk.net Guest
|
Posted: Tue Jan 31, 2006 11:00 am Post subject: Re: restricting memory |
|
|
| Thanks, a counter, keeping track of memory useage that is a good way. |
|
| Back to top |
|
 |
Ben Pope Guest
|
Posted: Tue Jan 31, 2006 12:00 pm Post subject: Re: restricting memory |
|
|
vfunc (AT) talktalk (DOT) net wrote:
| Quote: | Thanks, a counter, keeping track of memory useage that is a good way.
|
*Please* quote what you are referring to.
Ben Pope
--
I'm not just a number. To many, I'm known as a string... |
|
| Back to top |
|
 |
|