473,595 Members | 2,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Providing a no-overhead way for a contained class to access its container?

So far the only way that I found to do this was by making a
single global instance of the container class and providing
access to the contained class, through this single global
instance. Are there any other no-overhead ways that a
contained class can access its container?

The obvious choice of passing (a pointer or a reference to
the container) to the contained class is not a no-overhead
solution, it requires both memory and time. I am hoping that
there might be some obscure C++ syntax that provides the
capability that I am seeking, without the need to resort to
the single global instance of the container to provide
access.
Jun 27 '08 #1
36 2014
Peter Olcott wrote:
So far the only way that I found to do this was by making a
single global instance of the container class and providing
access to the contained class, through this single global
instance. Are there any other no-overhead ways that a
contained class can access its container?

The obvious choice of passing (a pointer or a reference to
the container) to the contained class is not a no-overhead
solution, it requires both memory and time. I am hoping that
there might be some obscure C++ syntax that provides the
capability that I am seeking, without the need to resort to
the single global instance of the container to provide
access.

It sounds like you may be asking the wrong thing. For one thing, you're
creating a tight-coupling between the contained and the container. This
prevents your contained objects from being in two separate containers at
the same time.

The other possible problem is the "no-overhead" requirement. Don't
optimize prematurely. Only worry about overhead when you find that
you're running out of memory, or that you're algorithm takes too long to
run. And then, use a profiler to determine exactly *where* your code
needs optimization.

I know its not the answer you're looking for, but I hope it helps you
non-the-less.

Good luck,
Daniel.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity .net/wordpress/>
Jun 27 '08 #2

"Daniel Pitts" <ne************ ******@virtuali nfinity.net>
wrote in message
news:48******** *************** @newsrazor.net. ..
Peter Olcott wrote:
>So far the only way that I found to do this was by making
a single global instance of the container class and
providing access to the contained class, through this
single global instance. Are there any other no-overhead
ways that a contained class can access its container?

The obvious choice of passing (a pointer or a reference
to the container) to the contained class is not a
no-overhead solution, it requires both memory and time. I
am hoping that there might be some obscure C++ syntax
that provides the capability that I am seeking, without
the need to resort to the single global instance of the
container to provide access.

It sounds like you may be asking the wrong thing. For one
thing, you're creating a tight-coupling between the
contained and the container. This prevents your contained
objects from being in two separate containers at the same
time.

The other possible problem is the "no-overhead"
requirement. Don't optimize prematurely. Only worry
about overhead when you find that you're running out of
memory, or that you're algorithm takes too long to run.
And then, use a profiler to determine exactly *where* your
code needs optimization.

I know its not the answer you're looking for, but I hope
it helps you non-the-less.

Good luck,
Daniel.
I already have a solution that meets all of my criteria,
what I am looking for is a cleaner solution. Either such a
solution exists, or it does not exist. If it does not exist,
then no further discussion is required, and my somewhat
clumsy solution will have to suffice.

The no-overhead requirement is a binding constraint that can
not be avoided. Adding any space or time overhead makes the
project infeasible. This project provides a solution where
alternative solutions do not exist, and this aspect of the
design provides the core functionality of the system.
--
Daniel Pitts' Tech Blog:
<http://virtualinfinity .net/wordpress/>

Jun 27 '08 #3
Peter Olcott ha scritto:
So far the only way that I found to do this was by making a
single global instance of the container class and providing
access to the contained class, through this single global
instance. Are there any other no-overhead ways that a
contained class can access its container?
You should think whether a solution is possible in any other programming
language, machine language included.
If it is not possible in machine language, of course it is possible
neither in C++.

The only solution I can think of is applicable only if your collections
occupy distinct memory pools. For example, if your collections are
arrays, you could check if the address of your object is between the
begin address and the end address of that array.
But that has a overhead though. To find the right array you have to loop
over all the arrays or something like that.

--
Carlo Milanesi
http://digilander.libero.it/carlmila
Jun 27 '08 #4

"Carlo Milanesi" <ca************ ********@libero .itwrote in
message news:48******** **************@ news.tiscali.it ...
Peter Olcott ha scritto:
>So far the only way that I found to do this was by making
a single global instance of the container class and
providing access to the contained class, through this
single global instance. Are there any other no-overhead
ways that a contained class can access its container?

You should think whether a solution is possible in any
other programming language, machine language included.
If it is not possible in machine language, of course it is
possible neither in C++.
I can do it in C++, but, the solution is clumsy. I am
looking for a less clumsy C++ solution, if one exists.
>
The only solution I can think of is applicable only if
your collections occupy distinct memory pools. For
example, if your collections are arrays, you could check
if the address of your object is between the begin address
and the end address of that array.
But that has a overhead though. To find the right array
you have to loop over all the arrays or something like
that.

--
Carlo Milanesi
http://digilander.libero.it/carlmila
I have a solution that allows the existence of multiple
instances of the container class, the number of such
instances can be specified at run-time. These multiple
instances would be stored in a single global
std::vector<Con tainerClass>. Another single instance global
integer would be used as the current subscript into this
std::vector<Con tainerClass>, specifying which ContainerClass
is being used. There would be no extra overhead in the use
of either the ContainerClass, nor its ContainedClass.
Jun 27 '08 #5
In article <ku************ *****@newsfe11. phx>, No****@SeeScree n.com
says...
>
"Alf P. Steinbach" <al***@start.no wrote in message
[ ... ]
Hm, that sounds like much bullshit and zero information,
iow., trolling.

www.SeeScreen.com
This technology can be applied to the automated testing of
video games. Video games are currently a $37 Billion annual
market, and all testing is done manually by human testers.
This looks like it retains the same level of information (i.e. none) and
adds only distraction. The question is exactly why you require zero
overhead for this particular aspect of a program. The annual revenues of
video games has nothing whatsoever to do with the question at hand.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 27 '08 #6

"Jerry Coffin" <jc*****@taeus. comwrote in message
news:MP******** *************** *@news.sunsite. dk...
In article <ku************ *****@newsfe11. phx>,
No****@SeeScree n.com
says...
>>
"Alf P. Steinbach" <al***@start.no wrote in message

[ ... ]
Hm, that sounds like much bullshit and zero
information,
iow., trolling.

www.SeeScreen.com
This technology can be applied to the automated testing
of
video games. Video games are currently a $37 Billion
annual
market, and all testing is done manually by human
testers.

This looks like it retains the same level of information
(i.e. none) and
adds only distraction. The question is exactly why you
require zero
overhead for this particular aspect of a program. The
annual revenues of
video games has nothing whatsoever to do with the question
at hand.
I was directly addressing your last remark, which itself
avoided rather than addressed the issue at hand. You really
don't need to know these details to answer my question. The
question is how can a contained class access its container
without adding any overhead? It seems like you are saying
(in a very convoluted way) that you simply don't know. Good
enough, no need for further discussion.
>
--
Later,
Jerry.

The universe is a figment of its own imagination.
YES, I agree!
Jun 27 '08 #7
In article <2X************ *****@newsfe11. phx>, No****@SeeScree n.com
says...
>
"Jerry Coffin" <jc*****@taeus. comwrote in message
news:MP******** *************** *@news.sunsite. dk...
In article <ku************ *****@newsfe11. phx>,
No****@SeeScree n.com
says...
>
"Alf P. Steinbach" <al***@start.no wrote in message
[ ... ]
Hm, that sounds like much bullshit and zero
information,
iow., trolling.

www.SeeScreen.com
This technology can be applied to the automated testing
of
video games. Video games are currently a $37 Billion
annual
market, and all testing is done manually by human
testers.
This looks like it retains the same level of information
(i.e. none) and
adds only distraction. The question is exactly why you
require zero
overhead for this particular aspect of a program. The
annual revenues of
video games has nothing whatsoever to do with the question
at hand.

I was directly addressing your last remark, which itself
avoided rather than addressed the issue at hand.
This was the first post I'd made to this thread, so none of your remarks
shows any sign of addressing anything I'd said previously.
You really
don't need to know these details to answer my question. The
question is how can a contained class access its container
without adding any overhead? It seems like you are saying
(in a very convoluted way) that you simply don't know. Good
enough, no need for further discussion.
I'm not saying I do or don't know -- I simply pointed out a serious
problem with your post. Unfortunately, I don't have a direct answer to
your question, largely because I don't think your question is entirely
clear -- in particular, while you say absolutely no overhead is allowed,
you don't say whether it's purely time overhead, space overhead, or both
that must be eliminated to qualify.

My guess is that there is no real answer -- if there is a possibility of
more than one collection to which an object might belong, _something_
must record which for the program to know -- and no matter how careful
one is to minimize that, it must still exist. Likewise if/when (for one
example) an object is moved from one collection to another, that
something must be updated to match -- and, again, no matter how
carefully that update time is optimized, it can never be reduced to
zero.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 27 '08 #8
On Jun 15, 10:35 am, "Peter Olcott" <NoS...@SeeScre en.comwrote:
"Carlo Milanesi" <carlo.milanesi .no.s...@libero .itwrote in
messagenews:48* *************** ******@news.tis cali.it...
Peter Olcott ha scritto:
So far the only way that I found to do this was by making
a single global instance of the container class and
providing access to the contained class, through this
single global instance. Are there any other no-overhead
ways that a contained class can access its container?
You should think whether a solution is possible in any
other programming language, machine language included.
If it is not possible in machine language, of course it is
possible neither in C++.

I can do it in C++, but, the solution is clumsy. I am
looking for a less clumsy C++ solution, if one exists.
The only solution I can think of is applicable only if
your collections occupy distinct memory pools. For
example, if your collections are arrays, you could check
if the address of your object is between the begin address
and the end address of that array.
But that has a overhead though. To find the right array
you have to loop over all the arrays or something like
that.
--
Carlo Milanesi
http://digilander.libero.it/carlmila

I have a solution
That is not a solution to the question you have in the subject line.
You are asking whether the contained class can have access to the
container without any overhead. No, it cannot.

Then you're providing a solution where a particular class has access
to particular instances of containers.

The fact that you *limit* the access to a certain class doesn't make
that a solution of "some class accessing its container." What you have
is a solution where everybody can access globals. That has been there
for decades.
that allows the existence of multiple
instances of the container class, the number of such
instances can be specified at run-time. These multiple
instances would be stored in a single global
std::vector<Con tainerClass>.
And that's no memory overhead?
Another single instance global
integer would be used as the current subscript into this
std::vector<Con tainerClass>,
How about that one? That is both a memory overhead and a time
overhead, because you need to manage it in non-zero time.
specifying which ContainerClass
is being used. There would be no extra overhead in the use
of either the ContainerClass, nor its ContainedClass.
When an object "uses" the container, it does it so because some time
has been spent to set the global(s) properly. That is overhead.

You may have something else in mind but you are not asking that.

Ali
Jun 27 '08 #9

<ac******@gmail .comwrote in message
news:f0******** *************** ***********@m3g 2000hsc.googleg roups.com...
On Jun 15, 10:35 am, "Peter Olcott" <NoS...@SeeScre en.com>
wrote:
>"Carlo Milanesi" <carlo.milanesi .no.s...@libero .itwrote
in
messagenews:48 *************** *******@news.ti scali.it...
Peter Olcott ha scritto:
So far the only way that I found to do this was by
making
a single global instance of the container class and
providing access to the contained class, through this
single global instance. Are there any other
no-overhead
ways that a contained class can access its container?
You should think whether a solution is possible in any
other programming language, machine language included.
If it is not possible in machine language, of course it
is
possible neither in C++.

I can do it in C++, but, the solution is clumsy. I am
looking for a less clumsy C++ solution, if one exists.
The only solution I can think of is applicable only if
your collections occupy distinct memory pools. For
example, if your collections are arrays, you could
check
if the address of your object is between the begin
address
and the end address of that array.
But that has a overhead though. To find the right array
you have to loop over all the arrays or something like
that.
--
Carlo Milanesi
http://digilander.libero.it/carlmila

I have a solution

That is not a solution to the question you have in the
subject line.
You are asking whether the contained class can have access
to the
container without any overhead. No, it cannot.

Then you're providing a solution where a particular class
has access
to particular instances of containers.

The fact that you *limit* the access to a certain class
doesn't make
that a solution of "some class accessing its container."
What you have
is a solution where everybody can access globals. That has
been there
for decades.
>that allows the existence of multiple
instances of the container class, the number of such
instances can be specified at run-time. These multiple
instances would be stored in a single global
std::vector<Co ntainerClass>.

And that's no memory overhead?
>Another single instance global
integer would be used as the current subscript into this
std::vector<Co ntainerClass>,

How about that one? That is both a memory overhead and a
time
overhead, because you need to manage it in non-zero time.
>specifying which ContainerClass
is being used. There would be no extra overhead in the
use
of either the ContainerClass, nor its ContainedClass.

When an object "uses" the container, it does it so because
some time
has been spent to set the global(s) properly. That is
overhead.

You may have something else in mind but you are not asking
that.

Ali
With my solution there is no additional memory or time
required for the contained class to access its container
over and above the memory and time required for any class to
access any other class.
Jun 27 '08 #10

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

Similar topics

1
1921
by: Nobody | last post by:
I have a website that is built around a web-application that my company purchased. My company has full ownership and administrative rights to this software and its corresponding files. It uses HTTP Basic Authentication and that cannot be changed at all (it is compiled into the web-application itself). This is my problem: We have a secure subnet (a customer of ours) that regularly uses this website and they don't want to have to log...
3
3432
by: N?ant Humain | last post by:
I have just begun learning Python so that I can write a simple script to make modification of a file used by another Python script easier. This file is basically a list of regular expressions. What I want to do is allow the user to select one of these regular expressions to modify, but I've realized I know of no way to provide a default value for user input. I could choose to show the regular expression the user has chosen and simply allow...
4
1250
by: New MSSQL DBA | last post by:
hi all, I am considering what should be the best way of implementing the following requirement. I've got a SQL2K production server. Now I've got another machine as the standby machine for this server so I'm thinking what method should I be using for this. Should I be using log shipping or Replication? Or if it's replication, what kind of replications should it be?
4
3266
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the program is doing I show a window which contains a progress bar and a label. At some point during the execution the state of the calculation is changed, so I want to let the user know this. I have placed the creation of the form in a seperate thread...
21
8744
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would like to include the ability to edit an existing value (drawn from an SQLite table) using a DOS console Python app, but my gut
0
967
by: Lee | last post by:
Once the business logic has been written and the basic elements are built into a page, what is the recommended way to provide the site innards to graphics design people without providing source code too? Thanks for advice. -- Warm Regards, Lee
1
1153
by: Billy | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table using ADO. I'm getting sometimes correct values, sometimes null values (when I know I pass a valid default value) and other times multiple values! I know what the values coming over are because I do a response.write to see it before the error...
0
1131
by: Adam Sandler | last post by:
Hello, Having an issue with my ASP.Net page. I use some COTS, which for all intents and purposes, simply makes a jpeg file and physically places it in a directory on the web server. The page load codebehind, makes a connection to the jpeg creation service and gets the path of the newly created image.
8
1444
by: AKS | last post by:
Hi! Here's a small test case (for Firefox): var o = { p: { func: function () {}, }, test: function () { var msg = ; var d = new Date;
0
1309
by: watches0898 | last post by:
Edwards Garments Company is one popular industry specific designer specializing in work wear that ranges from chef coats to chef hats to separates to housecleaning uniforms. Edwards Garments Company has a reputation for providing a high quality, affordable solution to the professional man's or woman's wardrobe. Often, white is the color given most focus, but a variety of colors are offered to wet your appetite, so to speak. ...
0
7882
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8260
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
8379
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
8017
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
8250
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...
1
5837
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3872
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2391
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
1
1490
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.