Modify getting_started example_c code to an In-Memory application

I am learning Berkeley DB In-Memory Application. I use
db-4.7.25/examples_c as a base code and made a simply modifications. Please see
below. It appears that something I missed or I don't understand how to
write an In-Memory Application with Berkeley DB. It would be very
appreciated if you could point me where I missed and what I did wrong.
gettingstarted_common.c:
/* Opens a database */
int
open_database(DB **dbpp, const char *file_name,
const char program_name, FILE error_file_pointer,
int is_secondary)
DB dbp;    / For convenience */
u_int32_t open_flags;
int ret;
/* Initialize the DB handle */
ret = db_create(&dbp, NULL, 0);
if (ret != 0) {
fprintf(error_file_pointer, "%s: %s\n", program_name,
db_strerror(ret));
return (ret);
/* set the cache size here */
ret = dbp->set_cachesize(dbp,
0, /* 0 gigabytes */
10 * 1024 * 1024, /* 10 megabytes */
1); /* create 1 cashe, all memory will
* be allocated contigously */
if (ret != 0){
dbp->err(dbp, ret, "Database open failed");
return (ret);
/* Point to the memory malloc'd by db_create() */
*dbpp = dbp;
/* Set up error handling for this database */
dbp->set_errfile(dbp, error_file_pointer);
dbp->set_errpfx(dbp, program_name);
* If this is a secondary database, then we want to allow
* sorted duplicates.
if (is_secondary) {
ret = dbp->set_flags(dbp, DB_DUPSORT);
if (ret != 0) {
dbp->err(dbp, ret, "Attempt to set DUPSORT flags failed.",
file_name);
return (ret);
/* Set the open flags */
open_flags = DB_CREATE; /* Allow database creation */
/* Now open the database */
ret = dbp->open(dbp, /* Pointer to the database */
NULL, /* Txn pointer */
NULL, /* File name */
file_name, /* Logical db name */
DB_BTREE, /* Database type (using btree) */
open_flags, /* Open flags */
0); /* File mode. Using defaults */
if (ret != 0) {
dbp->err(dbp, ret, "Database '%s' open failed.", file_name);
return (ret);
return (0);
/* opens all databases */
int
databases_setup(STOCK_DBS my_stock, const char program_name,
FILE *error_file_pointer)
int ret;
const char *db_vendor = "in_mem_vendor";
const char *db_inventory = "in_mem_inventory";
const char *db_itemname = "in_mem_itemname";
/* Open the vendor database */
ret = open_database(&(my_stock->vendor_dbp),
// my_stock->vendor_db_name,
db_vendor,
program_name, error_file_pointer,
PRIMARY_DB);
if (ret != 0)
* Error reporting is handled in open_database() so just return
* the return code.
return (ret);
/* Open the inventory database */
ret = open_database(&(my_stock->inventory_dbp),
// my_stock->inventory_db_name,
db_inventory,
program_name, error_file_pointer,
PRIMARY_DB);
if (ret != 0)
* Error reporting is handled in open_database() so just return
* the return code.
return (ret);
* Open the itemname secondary database. This is used to
* index the product names found in the inventory
* database.
ret = open_database(&(my_stock->itemname_sdbp),
// my_stock->itemname_db_name,
db_itemname,
program_name, error_file_pointer,
SECONDARY_DB);
if (ret != 0)
* Error reporting is handled in open_database() so just return
* the return code.
return (0);
* Associate the itemname db with its primary db
* (inventory db).
my_stock->inventory_dbp->associate(
my_stock->inventory_dbp, /* Primary db */
NULL, /* txn id */
my_stock->itemname_sdbp, /* Secondary db */
get_item_name, /* Secondary key creator */
0); /* Flags */
printf("databases opened successfully\n");
return (0);
example_database_load.c:
* Loads the contents of vendors.txt and inventory.txt into
* Berkeley DB databases. Also causes the itemname secondary
* database to be created and loaded.
int
main(int argc, char *argv[])
STOCK_DBS my_stock;
int ch, ret;
size_t size;
char basename, inventory_file, *vendor_file;
/* Initialize the STOCK_DBS struct */
initialize_stockdbs(&my_stock);
/* Initialize the base path. */
basename = "./";
/* Parse the command line arguments */
while ((ch = getopt(argc, argv, "b:h:")) != EOF)
switch (ch) {
case 'h':
if (optarg[strlen(optarg)-1] != '/' &&
optarg[strlen(optarg)-1] != '\\')
return (usage());
my_stock.db_home_dir = optarg;
break;
case 'b':
if (basename[strlen(basename)-1] != '/' &&
basename[strlen(basename)-1] != '\\')
return (usage());
basename = optarg;
break;
case '?':
default:
return (usage());
/* Identify the files that will hold our databases */
// set_db_filenames(&my_stock);
/* Find our input files */
size = strlen(basename) + strlen(INVENTORY_FILE) + 1;
inventory_file = malloc(size);
snprintf(inventory_file, size, "%s%s", basename, INVENTORY_FILE);
size = strlen(basename) + strlen(VENDORS_FILE) + 1;
vendor_file = malloc(size);
snprintf(vendor_file, size, "%s%s", basename, VENDORS_FILE);
/* Open all databases */
ret = databases_setup(&my_stock, "example_database_load", stderr);
if (ret) {
fprintf(stderr, "Error opening databases\n");
databases_close(&my_stock);
return (ret);
ret = load_vendors_database(my_stock, vendor_file);
if (ret) {
fprintf(stderr, "Error loading vendors database.\n");
databases_close(&my_stock);
return (ret);
ret = load_inventory_database(my_stock, inventory_file);
if (ret) {
fprintf(stderr, "Error loading inventory database.\n");
databases_close(&my_stock);
return (ret);
/* close our environment and databases */
databases_close(&my_stock);
printf("Done loading databases.\n");
return (ret);
example_database_read.c:
* Searches for a inventory item based on that item's name. The search is
* performed using the item name secondary database. Displays all
* inventory items that use the specified name, as well as the vendor
* associated with that inventory item.
* If no item name is provided, then all inventory items are displayed.
int
main(int argc, char *argv[])
STOCK_DBS my_stock;
int ch, ret;
char *itemname;
/* Initialize the STOCK_DBS struct */
initialize_stockdbs(&my_stock);
/* Parse the command line arguments */
itemname = NULL;
while ((ch = getopt(argc, argv, "h:i:?")) != EOF)
switch (ch) {
case 'h':
if (optarg[strlen(optarg)-1] != '/' &&
optarg[strlen(optarg)-1] != '\\')
return (usage());
my_stock.db_home_dir = optarg;
break;
case 'i':
itemname = optarg;
break;
case '?':
default:
return (usage());
/* Identify the files that hold our databases */
// set_db_filenames(&my_stock);
/* Open all databases */
ret = databases_setup(&my_stock, "example_database_read", stderr);
if (ret != 0) {
fprintf(stderr, "Error opening databases\n");
databases_close(&my_stock);
return (ret);
if (itemname == NULL)
ret = show_all_records(&my_stock);
else
ret = show_records(&my_stock, itemname);
/* close our databases */
databases_close(&my_stock);
return (ret);
Run test results:
[user@localhost in_memory]$ ls
build_command.txt example_database_read.c gettingstarted_common.h load vendors.txt
example_database_load.c example_database_read.o gettingstarted_common.o makefile
example_database_load.o gettingstarted_common.c inventory.txt read
[user@localhost in_memory]$ ./load
databases opened successfully
databases closed.
Done loading databases.
[user@localhost in_memory]$ ls
build_command.txt example_database_read.c gettingstarted_common.h load vendors.txt
example_database_load.c example_database_read.o gettingstarted_common.o makefile
example_database_load.o gettingstarted_common.c inventory.txt read
[user@localhost in_memory]$ ./read -i "Zulu Nut"
databases opened successfully
No records found for 'Zulu Nut'
databases closed.
[user@localhost in_memory]$ ./read
databases opened successfully
databases closed.

Hello. This behavior looks correct to me, could you please specify what you were expecting to see?
load creates an in-memory database because you don't specify a file name, and that database is lost when load finishes. If you want a database to persist after a program exits, it needs to be written to disk.
Ben Schmeckpeper

Similar Messages

  • Modifying default html code used for publishing

    Apologies if this is a duplicate - my machine locked up.
    To meet security requirements of our site -- I need to have
    the references in the html code generated when publishing swf
    w/html use https rather than http.
    I've found references to modifying the html code generated
    but wondered if there is a way to modify the default code rather
    than each time I publish. I found the references in two places in
    the html: codebase="
    http://download... and pluginspage="
    http://www.macromedia... The
    company that reviewed us needs to have these both reference https
    rather than http.
    Any suggestions? Thanks!

    Hi hdms and welcome to our community
    Indeed, Captivate has "seed" files that it uses. You should
    probably investigate modifying them.
    For Captivate 1, look here:
    C:\Program Files\Macromedia\Captivate\Templates\Publish
    For Captivate 2, look here:
    C:\Program Files\Adobe\Adobe Captivate 2\Templates\Publish
    Cheers... Rick

  • OS X says that Compressor was modified since the code sign and won't let me launch it. Any reasoning behind this?

    Hello
    After updating Compressor to the most recent version (4.2), I get a message saying that Compressor was modified since the code sign and then won't let me launch it.
    I have tried reinstalling Compressor restarting and updating my computer.
    Any reasoning behind this problem??
    Thanks
    I am running OS X Yosemite 10.10.3 on a 2013 13inch MacBook Pro, 8GB RAM, 2.8GHz i7.

    Start the computer from the installation disk and perform Repair Disk and Repair Permissions using Disk Utility

  • [svn:osmf:] 13855: Modify plugin framework code to automatically pass MediaFactory to PluginInfo .initializePlugin via the existing metadata namespace.

    Revision: 13855
    Revision: 13855
    Author:   [email protected]
    Date:     2010-01-28 09:44:32 -0800 (Thu, 28 Jan 2010)
    Log Message:
    Modify plugin framework code to automatically pass MediaFactory to PluginInfo.initializePlugin via the existing metadata namespace.  Update unit tests.
    Modified Paths:
        osmf/branches/sprint9-candidate/framework/OSMF/org/osmf/plugin/PluginLoader.as
        osmf/branches/sprint9-candidate/framework/OSMFTest/org/osmf/plugin/TestPluginManager.as

    Revision: 13855
    Revision: 13855
    Author:   [email protected]
    Date:     2010-01-28 09:44:32 -0800 (Thu, 28 Jan 2010)
    Log Message:
    Modify plugin framework code to automatically pass MediaFactory to PluginInfo.initializePlugin via the existing metadata namespace.  Update unit tests.
    Modified Paths:
        osmf/branches/sprint9-candidate/framework/OSMF/org/osmf/plugin/PluginLoader.as
        osmf/branches/sprint9-candidate/framework/OSMFTest/org/osmf/plugin/TestPluginManager.as

  • H87M-P33 bios hangs (code 99) when both memory modules installed

    Hello everyone!
    MB: H87M-P33
    CPU: Intel Core I5-4670
    RAM: Corsair Vengeance LP 2x4GB kit 1600MHz 9-9-9-24 1.5V (CML8GX3M2A1600C9B)
    PSU: Corsair CX500
    Besides power button, nothing else is connected.
    I'm building a brand new system. It boots with either module from the memory kit in either slot, but bios hangs (code 99) when BOTH memory modules are installed.
    I tried to update bios to v2.1, but still won't boot with both modules installed.
    Then I looked on the global site and found v2.2 bios for this board, which states "- Improved memory compatibility." and released on 2013-08-19, which is fairly recently. I tried to download it from download site (US, EU, CHN) but all sites give 404 error (file not found) to me.
    Link to MB:
    wwwDOTmsi.com/product/mb/H87M-P33.html#/?div=BIOS
    Links for downloads I tried and give 404 to me:
    download1.msi.com/files/downloads/bos_exe/7817v22.zip
    download2.msi.com/files/downloads/bos_exe/7817v22.zip
    download3.msi.com/files/downloads/bos_exe/7817v22.zip
    I hope you guys can help me.

    Quote from: klapaucius on 12-September-13, 15:10:43
    It boots fine with a single stick in either slot. I tried flashing the attached beta bios via UEFI interface (choose the option with ME) and it updated. It still won't work if both slots are filled, works fine if either of dimm slots is filled with either stick from the kit.
    ADD: I also tried putting whole RAM kit in my main machine and it works, so RAM isn't faulty.
    Use a single RAM module, boot up, access the BIOS and be sure XMP is disabled.
    Set the timings to 9-9-9-24, the voltage to 1.55-1.60V and the speed to 1333MHz.
    Save the settings, shut down, insert the 2nd RAM module and see if it works.

  • [svn] 4804: Bugs: LCDS-548: add code to deal with contentType="application/ xml" with one parameter (avoid

    Revision: 4804
    Author: [email protected]
    Date: 2009-02-02 17:56:22 -0800 (Mon, 02 Feb 2009)
    Log Message:
    Bugs: LCDS-548: add code to deal with contentType="application/xml" with one parameter (avoid
    name/value encoding in that case)
    LCDS-405: baseURL on HTTPMultiService should accept URLs which start with "/"
    Added convertParametersHandler and convertResultsHandler function hooks to RemoteObject
    to support framework code which wants to modify the service behavior.
    Moved "properties" from rpc/http/AbstractOperation to rpc/AbstractOperation so we can use
    it for customizing the handling of remote object results
    Couple of minor ASDoc fixes and one tab -> spaces change
    Doc: minor asdoc edits
    QE: LCDS QE will verify the bugs in this one
    Reviewers: Mete, Pete, Seth, Ed reviewed different parts of this checkin
    Ticket Links:
    http://bugs.adobe.com/jira/browse/LCDS-548
    http://bugs.adobe.com/jira/browse/LCDS-405
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/AbstractInvoker.as
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/AbstractOperation.as
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/http/AbstractOperation.as
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/http/HTTPMultiService.as
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/http/Operation.as
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/remoting/Operation.as
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/remoting/RemoteObject.as

    Hello,
    How about this as an alternative:
    Use a functional global which has 3 cases:
    1. open config file - it opens the config file and reads the contents into a string (which is the functional global data), and you only do this one time at the beginning of the program.
    2. edit config data - it edits the string, which are really the contents of the file, but doesn't worry about writing to the file.  you could even get fancy here, and allow an array of tags and an array of values as input, and it would go update/edit all the tags to have the corresponding values.
    3.  close config file - it writes the current string data (the functional global data) to the file and closes it.
    Using the functions in the string palette, I think you'll find most of the code for that module/functional global will be easy to write.
    I hope this helps!
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • T-code for delete file from application server

    Hi all!
    Please, has any t-code for delete file from application server? For upload exist CG3Z, for download has CG3Y. And for delete? Has anyone?
    I need to delete file from application server in QA system and i don't want to create a program for this because i will need to transport a request from DEV to QA.

    I don't have contact with basis team.
    The FM EPS_DELETE_FILE support directory name with max 60 char. My dir. has more than that. I need a transaction for this.
    Anybody know if this transaction exist?

  • How to include html page or html code in adobeflex 4 web application please give me a solution.

                     How to include html page or html code in adobeflex 4 web application please give me a solution.
                       Thank you
                       Chandra Sekhar

    hi,
    go thru this link, may be of some help for you
    About IFrames
    http://www.deitte.com/archives/2006/08/finally_updated.htm
    IFrame Src
    http://code.google.com/p/flex-iframe/
    About the IFrame Approach
    http://www.deitte.com/archives/2008/07/dont_use_iframe.htm

  • How can Modify the Text of a MessageArea in a Application WD ABAP Standard?

    Dear Experts.
    How can Modify the Text of a MessageArea in a Application WD ABAP Standard?
    I found the following link in the helpsap, but in this moment I don't know How found this text? and Modify this text with a new text.
    http://help.sap.com/saphelp_nw70/helpdata/en/3a/f6ba42a950da11e10000000a155106/frameset.htm
    The text of a MessageArea are in a table of configuration or can do the system for get this text and show in the application in the portal? How can get this and modify by a new text.
    Please help me with a suggestions.
    Thanks
    Regards
    Carmen G.

    Dear Kranthi..
    The datas of the Application is the following:
    General Information About the Application and Component
    Application: FITE_REQUEST
    Web Dynpro Component: FITV_FPM
    Window Information: FPM_WINDOW
    View Information: Layout_view
    Information on Field
    Field ID: HELPTEXT
    Type of UI Element : Explanation
    Attributes of UI Element
    TEXT_DOCUMENT_NAME: FITE_FPM_REQUEST_GENERAL_DA
    I dont found this method L_MESSAGE_MANAGER->REPORT_T100_MESSAGE.
    Please can give more suggestions for found the method
    Thanks in advance
    Regards
    Carmen G.

  • Compiling java code from a running java application

    How does compiling of java code from a running java application work?
    I found a class: com.sun.tools.apt.main.JavaCompiler
    but cannot find any documentation of how this class works.

    How does compiling of java code from a running java
    application work?Probably most reliably using Runtime.exec().
    I found a class:
    com.sun.tools.apt.main.JavaCompiler
    but cannot find any documentation of how this class
    works.For a purpose. You are not supposed to use this class. With the next JRE release or implementation, it might not exist anymore - it's not part of the standard API.

  • In memory application using set_cachesize!!!

    set_cachesize 1GB
    DB_SYSTEM_MEM is used
    only logic name of database is used
    "ipcs -m" shows 1GB used in shared memory
    can I create an in memory application without using set_catchsize?
    does it possible to control the cache size at runtime?

    269f0e65-9669-4d4e-87a3-5a144d0a5733 wrote:
    can I create an in memory application without using set_catchsize?
    set_cachesize has nothing to do with creating an in-memory application or not. It configures the size of the cache ( http://docs.oracle.com/cd/E17076_03/html/programmer_reference/general_am_conf.html#am_conf_cachesize ), which is in memory. In order to learn how to create an in-memory application, please read: http://docs.oracle.com/cd/E17076_03/html/programmer_reference/program_ram.html
    269f0e65-9669-4d4e-87a3-5a144d0a5733 wrote:
    does it possible to control the cache size at runtime?
    Yes, by using DB_ENV->set_cachesize(). The supplied size will be rounded to the nearest multiple of the region size and may not be larger than the maximum size configured with DB_ENV->set_cache_max().
    DB_ENV->set_cachesize - http://docs.oracle.com/cd/E17076_03/html/api_reference/C/envset_cachesize.html
    Bogdan

  • Error code 0x645(1605) when using application supersedence

    I've created a new version of an application that supersedes the previous version. I'd like the new version to uninstall the previous version, as otherwise it will install alongside it. Each version has a different MSI product code.
    I created the application for the new version along with the supersedence rule, setting it to uninstall the previous version. I then set up a test VM with the old application and tried to install the new one via the Application Catalog. However, when the
    Software Center begins the installation and tries to remove the old version, it fails with: "The software change returned error code 0x645(1605)"
    I verified that the uninstall string for the old version is correct: I can even manually run it on the VM and it begins to uninstall the old version. I thought that 1605 indicated that the product that's trying to be removed is not present, but since the
    uninstall string works I'm not certain what exactly is going on.
    Any help that can be offered would be most appreciated. Thank you!

    Thanks for responding so quickly! I ran it manually and the new version of the program installs ok. I used the same command line that I specified in the MSI deployment type (and there's only the one deployment type). So it seems that the error occurs when
    SCCM implements the supersedence rule and tries to uninstall the old version.
    I checked Event Viewer and I see two entries for when the program is attempting to uninstall, but they are simply the entries that say "beginning a windows installer transaction" and "ending a windows installer transaction." There's no error in Event Viewer.
    The entries feature the MSI product code of the product; if I copy that product code and run msiexec /x with it, it uninstalls.

  • Memory applications HDD increased to 718 GB after the installation yosemity.

    After the installation of yosemity, memory applications HDD increased to 718 GB, increasing every other day 2 GB.

       Re-index Macintosh HD.
       Do this twice.
       Spotlight reindexing will take a while to finish.
       System Preferences > Spotlight > Privacy
       http://support.apple.com/kb/ht2409
       You will see a new category  “Other” in the Storage Display.
          About “Other”:
       http://support.apple.com/en-us/HT202867

  • Q: ABAP code from db to memory decreases performance?

    Hi Gurus,
    We have a problem with some ABAP code (a start routine in a BI load). Basically the situation is: we had some code that builds a hierarchy (and inserts into hierarchy table) based on an attribute load, which worked fine but was to slow.
    As we do not need the hierarchy anymore we changed the code to only build the hierarchy in memory (the reason why we need it at all is because building this is the only way we can ensure to load the right records in the attribute load) and now, it is sloweru2026.which we do not understand.
    In general we have replaced:
    SELECT SINGLE * FROM /BIC/HZTVFKORG INTO nodelast
      WHERE nodeid = lastnode2.
    With:
      READ TABLE VirtHierarchy INTO nodelast
        WITH KEY nodeid = lastnode2.
    And replaced:
      UPDATE /BIC/HZTVFKORG FROM nodelast.
    With:
      MODIFY TABLE VirtHierarchy FROM nodelast.
    And replaced:
      INSERT INTO /BIC/HZTVFKORG VALUES node.
    With:
      APPEND node TO VirtHierarchy.
    As we see it, this should increase the performance of the start routine and the load (it takes several hours for just 50000 records), but it is actually running slower now...
    Does anybody have any idea about why this is not improving performance?
    Thank you in advance,
    Mikael

    Dear Mikael Kilaker,
    There are few reason:
    1. Data overload in memory.
    , if you try to execute
    SELECT SINGLE * FROM /BIC/HZTVFKORG INTO nodelast
    WHERE nodeid = lastnode2.
    With:
    READ TABLE VirtHierarchy INTO nodelast
    WITH KEY nodeid = lastnode2.
    And replaced:
    UPDATE /BIC/HZTVFKORG FROM nodelast.
    With:
    MODIFY TABLE VirtHierarchy FROM nodelast.
    And replaced:
    INSERT INTO /BIC/HZTVFKORG VALUES node.
    With:
    APPEND node TO VirtHierarchy.
    inside any loop conditions, this approach will make the system slow because it will load entire table into memory then system still need to cater space for selected value thus make system not really effective when you execute large volume of data.
    2. Unsorted data.
    It is really great practice if you sort nodelast. It is extra steps but the effect greatly decreased response time when system manipulating sorted data in the internal table.
    3. Use binary search in READ table.
    Try to use this code
    READ TABLE VirtHierarchy INTO nodelast
    WITH KEY nodeid = lastnode2 BINARY SEARCH.
    this practice also will increase performance when you execute large data inside internal table.
    Do reward points if this helps you

  • Modify javadoc source code

    Hello :-)
    I would like to use javadoc to read comments inside the methods, but i know there is no such thing in javadoc now so i am thinking either to implement this feature myself or find other documentation generators to use. Does anyone has any good ideas on how to do it???
    Have anyone done such thing already? I know i can get javadoc source code from tools.jar, butt confused on how to modify it and build it or making the jar on that... Thanks a lot....

    Hi,
    Check the below note 872892 gives you step by step procedure of how to do the changes.
    The below links will be of help to understand the concepts:
    http://help.sap.com/saphelp_nw04/helpdata/en/1c/ccabc5ef780f4cb5be6b9624b077cd/frameset.htm
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=%28J2EE3417400%29ID0042988250DB11232412343044179198End?blog=/pub/wlg/7177
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c0b1f2c8-54e0-2910-9ab3-b85f15093655?prtmode=navigate
    http://help.sap.com/saphelp_nw04/helpdata/en/4e/a5214174abef23e10000000a155106/content.htm
    Cheers-
    Pramod

Maybe you are looking for