473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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?

Jan 30 '06 #1
7 1522
vf***@talktalk.net wrote:
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?
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
Jan 30 '06 #2
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.

Jan 31 '06 #3
vf***@talktalk.net wrote:
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
Jan 31 '06 #4
vf***@talktalk.net wrote:
Instances possibly but otherwise no, that is not what I am asking.
Please quote what you are referring to.
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?
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...
Jan 31 '06 #5
Thanks, a counter is the way.

Jan 31 '06 #6
Thanks, a counter, keeping track of memory useage that is a good way.

Jan 31 '06 #7
vf***@talktalk.net wrote:
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...
Jan 31 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xenophobe | last post by:
I have a popup window (required by the client) containing a form and would like to prevent users from accessing it directly. They are instead required to access the page via a hyperlink on another...
4
by: Dennis C. Drumm | last post by:
Is there a way with C# to allow one class access to a method or field of another class, without making that method or field visible to all other classes, as would be the case when making the method...
3
by: volume | last post by:
Restricting a windows textbox (edit item) to digits only. Is there a windows option, using .NET C#, to only allow a user to enter digits ONLY? If so, what is the flag or setting? If no, what is...
0
by: CLEAR-RCIC | last post by:
Hi. I'm using web controls in my web application. Using IIS, I am trying to restrict an IP address from viewing one of my contols. When I restrict the IP Address using the Directory Security tab...
1
by: Piper707 | last post by:
Hi, I'd like to know if there are any more ways of restricting an XML document to having only non-empty tags (containing Strings). I can think of 2 ways: 1) <xs:simpleType name="tagName">
3
by: vj | last post by:
I'm building a large infrastructure with about 30 servers (all running linux). I allow my end users to write scripts which then get broken down in smaller parts and run across the 30 servers. The...
2
by: Brett Romero | last post by:
I have a CustomDataGrid that inherits DataGrid. I use the filter below via a context menu, which works fine. ( ( DataTable ) this.DataSource ).DefaultView.RowFilter = filterexpress; The...
0
by: WebMatrix | last post by:
Hello, What's the best way to keep email templates as html files on the server, so ASP.NET application can get file access to it, while restricting web users from accessing it through their...
8
by: sneddo | last post by:
Ok I am trying to do the above, I have got a script that will restrict the length but it requires the user to enter the field and hit a key, before it will work. This would normaly be find, but...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.