473,624 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1528
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(thatclas s)). IOW, take your
1 Mb and divide it by (sizeof(thatcla ss)) 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
2704
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 page. HTTP_REFERER, while not completely reliable, would serve the purpose except for another problem. The hyperlink points to a JavaScript function which opens the popup. This yields HTTP_REFERER worthless. My other thought was to create a...
4
4625
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 or field public? Thanks, Dennis
3
4658
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 the best method to manually and robustly do it? I have a windows form with an editbox that I only want user's to enter digits. Thanks in advance.
0
1010
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 on properties in IIS, it doesn't seem to work. If I try to restrict a .htm file in the same application it does work. Does restricting by IP address not work with web controls?
1
2167
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
1265
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 results from each individual run are combined and presented back to the user. I'm currently using pylint to restrict access to many things and make the code a little more 'safe'. (I understand that it is very difficult, if not impossible, to...
2
2620
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 above gives me narrowed results via a right click on a grid cell. I filter on the cell value. I'd like to click another cell and filter again. For example, I start with 100 rows. I filter as above and get 50 rows. Now I want to filter on another...
0
991
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 browsers. The site is open to the public, no authentication is required, and web application runs under default iis user account. Thanks!
8
8706
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 the title field gets its information from a previouse page so its value can easily be over 40 chars. (I can not restrict the length on the previouse page.) The major dificulty is that there is no form on the aspx page, and I do not have access to...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.