473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

designing a scalable storage

i need to create a storage module which can store any thing the user
wants. I want it to handle almost any storage requirement, so that
clients can define their own key classes derived from the base key
class which is defined by the storage module itself.

for example:
in the storage module we have
class base_key
{
public:
bool operator < (const base_key& rhs) const = 0;
}

class storage
{
public:
void store(base_key& key, void* data);
void* withdraw(base_k ey& key);
}

and in the client code,
class my_key : public base_key
{
public:
bool operator < (const base_key& rhs) const
{
...
}
}

i know the above code does not work. I managed to do allow that
functionality somehow by
using lot of workarounds for lot of problems, and that code works
well, but im not sure whether it is the
best method to do this. Im wondering whether there are any standard
methods to provide this kind of functionality, so i can compare my
implementation with it.

thanks.
Jun 27 '08 #1
2 1559
On May 20, 12:39*pm, e2po...@yahoo.c om wrote:
i need to create a storage module which can store any thing the user
wants. I want it to handle almost any storage requirement, *so that
clients can define their own key classes derived from the base key
class which is defined by the storage module itself.
>
thanks.
struct base_key{
bool operator<(base_ key const&r){
return less_than(r);
}
protected:
virtual bool less_than(base_ key const&r)const=0 ;
};

struct mykey:base_key{

bool less_than(base_ key const&r)const{
mykey const& R= dynamic_cast<my key>(r);
return val<R.val;
}
private:
int val;

};
Lance
Jun 27 '08 #2
e2*****@yahoo.c om wrote:
[..]
Lance Diduck managed to infer the meaning of it and propose a
technique i can use to implement what i want. However it has some
problems when we compare two different types of keys. In the above
implementation, dynamic_cast will return NULL, if the cast is invalid.
What to do then? we cant just fail, we need to return either true or
false.
See, you're asking us to define your class behaviour. We can't. We
don't know the problem domain. In most cases if the two classes have
the same base class (siblings, so to speak) but both have data in
addition to the base class subobject, comparing them makes simply no
sense. In which case they shouldn't be allowed to serve as the sorting
attribute for any data. I believe that's the design flaw in your
scheme, and you need to overcome this before you can proceed to the
implementation.
To overcome this, i added an interger that identified the key class
type, and in the base class '<' operator, i can check for this
interger, and if they are equal call less_than, and if not return
something based on that interger. This works fine, but im not 100%
satisfied, as i think this kind of workarounds are not acceptable in
robust software.
therefore im planning to go for a template based solution for this.
I think you're not seeing the big picture. If you need storage that
works fast, you should use a hash table and let your clients' objects
define a hash code calculation but that hash code has to be of a fixed
type. You've come up with an integer. Is that enough? I don't know.

It seems that you're still on the fence. You want to provide the
clients with a way to store their data with a polymorphic key, but at
the same time your comparison requirement takes all the wind out of the
original idea (that would keep the key polymorphic) and instead you need
your key to be specific.

Now, how can templates help you? With templates if your clients will
provide the type of the key and its comparison function (or whatever
that would help sorting the keys), but you won't be able to put
different types from different clients in the same efficient storage,
they would need to be separate types. Now, wrap 'std::map<T, void*>',
provide the user with the ability to pick T, and you're done! Or are you?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #3

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

Similar topics

5
2766
by: Robert J. O'Hara | last post by:
For some time I've struggled with the problem of displaying simple captioned figures on webpages in a way that is robust and scalable. I tend to make "boring" (um, I mean "conservatively elegant") pages that are text-heavy and that resemble academic publications. Despite the origin of HTML in the world of scientific communication, the absence of a FIGURE element to serve as a counterpart to the TABLE element is surprising. This topic has...
3
1333
by: alexhong2001 | last post by:
When design a class, should always make it "derivable" as a base class? Is there really a situation that the designed class not "derivable"? When should make a member "protected"? Only when allowing the derived class(es) directly access it? Should destructor always be virtual? Thanks for your comments!
1
2425
by: .:: - Hades - ::. | last post by:
Hi, 1. I am trying to find out something close to the Overlapped IO / Completion Ports model provided to me by the Winsock 2 library in C#. The two ways provided to me to move towarsds scalable servers in C# would be - Asynchronous Sockets - Non-blocking Socket Methods
0
367
by: Jonas Hei | last post by:
I need to develop a scalable server which has to receive and send UDP messages. It is required to process hundreds of messages (coming from different remote computers) per second (possibly even thousands) and of course I would like to make it as performant and scalable as I can. The idea is that remote computers send data to this server. The remote computers will send data from any random port to port 28901 of my server. My server then...
0
1881
by: Namratha Shah \(Nasha\) | last post by:
Hey Group, After a long week end I am back again. Its nice and refreshing after a short vacation so lets get started with .NET once again. Today we will discuss about Isolated Storage. This is one of the topics which I find interesting as I feel that it has a lot of practical usage or applicability. We all know that all applications need some storage space to archive certain
0
1972
by: Itai | last post by:
I require implementing an internal messaging sub-system in asp.net website where users send messages to each other using their userid for the address. No SMTP / POP3 functionality required except in one case where I require sending an email notification to a user when new mail has arrived to his "internal mailbox". I am currently designing the solution and would very much appreciate to see similar solutions to the problem I'm facing. I...
1
1374
by: John Grandy | last post by:
Could someone point me in the direction of good discussions on scalable state management solutions? Specifically, pros and cons of following strategies: Strategy 1 : temporary business-objects are implicitly stored in RAM, "permanent" business objects are explicitly stored in SQL-Server Strategy 2 : both temporary and permanent business-objects are implicitly stored in SQL-Server
1
1332
by: James Conrad StJohn Foreman | last post by:
Hi, we've recently changed our db2 server from using a single RAID array to a SAN. (machine is running 8.2.4 UDB on SLES 9, 2.6 kernel, 32 bit Intel) If we'd been using a RAID array, then we'd be tuning prefetch size according to the number of discs and the stripe size. From what I understand of the SAN configuration, there's an abstraction layer between the physical storage and what gets presented to the machines
1
1473
by: PeteOlcott | last post by:
Does anyone know how to make a scalable image on a DialogBox? I am currently using a static Picture Control, can this be adapted to become scalable to the size of the DialogBox?
0
10071
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
10017
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
9882
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
8905
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
6690
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
5326
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
3987
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
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
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.