473,698 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing my recipes

Hello, I am currently designing a small program that's supposed to become a
helper program
for a computer game. The program is to store a number of recipes and this
collection of recipes
is expected to grow to quite big over time. Each recipe can be categorized
into one of several
categories, for example: wood-working, tailoring, brewing, blacksmithing
etc.
I am planning on having a base class Recipe and inherit a new class for each
category of recipe.
I also plan on having an Item class for each item that is used in a
recipe...and now to my problem,
several recipes use the same items...my program would consume a lot of
memory indeed if each
recipe that uses, for example, the item Water had its own copy of the Item
class instance describing water.
How should I solve that? Maybe assign a unique ID to each item (and maybe
each recipe) and have a global
item_map which maps item_IDs to items. So instead of storing objects of type
Item in the recipes
I store keys to this item map. Other alternatives? Hmm...ohh, and I need to
be able to serialize everything.
So what I am looking for is, ideally, a solution that can be implemented
using standard c++ that doesn't
consume too much memory and that allows for easy serialization.

Thanks for any input
Jul 22 '05 #1
1 1149
Eric Lilja wrote:
Hello, I am currently designing a small program that's supposed to become a
helper program
for a computer game. The program is to store a number of recipes and this
collection of recipes
is expected to grow to quite big over time. Each recipe can be categorized
into one of several
categories, for example: wood-working, tailoring, brewing, blacksmithing
etc.
I am planning on having a base class Recipe and inherit a new class for each
category of recipe.
I also plan on having an Item class for each item that is used in a
recipe...and now to my problem,
several recipes use the same items...my program would consume a lot of
memory indeed if each
recipe that uses, for example, the item Water had its own copy of the Item
class instance describing water.
How should I solve that? Maybe assign a unique ID to each item (and maybe
each recipe) and have a global
item_map which maps item_IDs to items. So instead of storing objects of type
Item in the recipes
I store keys to this item map. Other alternatives? Hmm...ohh, and I need to
be able to serialize everything.
So what I am looking for is, ideally, a solution that can be implemented
using standard c++ that doesn't
consume too much memory and that allows for easy serialization.

Some quick approaches:
1)

enum Item {WATER, RED_WINE};

class Spaggheti: public Recipe
{
std::vector<Ite m> items;

// ...
void some_func() const
{
if(items[0]==WATER)
// ...
}

// ...
};

2)

vector<string>I tems;

// ...
class Spaggheti: public Recipe
{
vector<string>: :const_iterator item;

// ...

public:
Spaggheti() { item=Items.begi n()+3; }

//...
void some_func() const
{
if(*item=="WATE R")
// ...
}

// ...
};


There are a lot of such "hacks" that can minimise memory use.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #2

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

Similar topics

3
3052
by: Mark | last post by:
I have a website with an increasing amount of articles and news reports and so I am thinking of moving away from storing each article as a seperate page to having a single page and storing articles in a databasewhich are retrieved using a GET parameter. I see the advantage to me in using this approach as being making use of MySQL's fulltext search capability and less work needed when updating the design of the page. I'm not sure of a few...
2
1315
by: Ringwraith | last post by:
Hello! I want to ask You the question about the licence of ASPN online Python Cookbook recipes. Under what licence are those recipes. If I want to use in my application some parts of the code from some recipe, should I place a statement saying who the author is, etc.? Best Regards, Niki
8
2580
by: barnesc | last post by:
I added some recipes to the Python Cookbook: - listmixin Use ListMixin to create custom list classes from a small subset of list methods: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440656 - pytime
5
1235
by: kadidarm | last post by:
Hi I have just started to make a Bill of Material Program (BOM) for my self using Microsoft Access 2003. I am looking to make a recipe database. The problem I am having is this: I have a table called tblRecipe is linked to tblRawMaerial. In building my BOM, tblRecipe needs to look up tblRawMaterial as well as tblRecipe itself because a product of a recipe can also be used to make another recipe. For example, to make chocolate chip...
5
3838
by: mma | last post by:
I have been using the lubksb routine in Visual C++ 6.0 and noticed what looks like an error to me. The last section of the method looks like this: for(i=n;i>=1;i--) { sum=b; for(j=i+1;j<=n;j++) sum -= a*b; b=sum/a;
5
3024
by: Edward Hua | last post by:
Hi, I'm wondering if anybody has ever copied the quicksort algorithm from the book Numerical Recipes in C: The Art of Scientific Computing (2nd ed.), by Press, Teukolsky, Vetterling, and Flannery, in Chapter 8. Quicsort is supposed to sort an array of, say, doubles, in ascending order. I tried to copy this algorithm line by line to test it. It seems that there's an error in this algorithm as given in this book. Namely, the
16
3264
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is that I'm not very experienced with pointers, pointers to pointers and the like and I got 4 compiler warnings + I don't completely understand how to build this "compact matrix" (see later).
23
15665
by: Abhi | last post by:
Hi.. I wanted the C source code in machine readable format for the book "Numerical Recipes in C". I got hold of the pdf version of the book somehow. Does anyone have the complete C code of the book?. If yes,..can you please mail me the code or somehow share it with me?. With Regards, Abhishek S
10
5419
by: Babak | last post by:
Hi, I've developed a C program which contains a large number of vectors and matrices operations. Throughout my code, I used the template from the Numerical Recipes book to define vectors and matrices and access their elements. For example, to define a vector I used the function: my_vector=vector(0,n-1); Which actually allocate the memory as follows:
0
8612
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
9171
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
9032
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
8905
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
8880
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
6532
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
5869
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
4373
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
3053
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

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.