Loading a large number of strings into memory quickly

Hello,
I'm working on an iPhone application where I need to load a large number of strings into memory. Currently I'm simply reading from a file where each string is stored in plain text on a single line. I read the file contents into a string using stringWithContentsOfFile and then I create an NSSet object using NSSet setWithArray:[string componentsSeparatedByString:@"\n"]];
This works like a charm but takes around 8 seconds to load on the iPhone. I'm looking for ways to speed this up. I've already tried a few things which weren't any faster:
1) I used [NSKeyedArchiver archiveRootObject:myList toFile:appFile]; to store the NSSet data structure. Then instead of reading the text file storage. I read this file using [NSKeyedUnarchiver unarchiveObjectWithFile:appFile]; This was actually very slow and created a strings file that was about 2x the size of the original plain text.
2) Instead of using an NSSet, I used and NSDictionary and used writeToFile and dictionaryWithContentsOfFile. This was also no faster.
3) Finally I tried using the NSDictionary to write to a binary file format using NSPropertyListSerialization. This was also not any faster.
I've been thinking about using SQLite instead of the flat file read, but I haven't had a chance to prototype that out to see if it would be faster. It's important that I can do fast searches for specific strings, which is why I originally used a set.
Does any one else have any ideas how to load this into memory faster? If all else fails, I'm simply going to load the strings into memory using a separate thread on application launch so I don't prevent the user from getting to the main menu for 8 seconds.
Thanks,
-Keith

I'd need to know more about what you're doing, but from what you're describing I think you should try to change your algorithm.
For example: Instead of distributing one flat file, split your list of strings into 256 files, based on the first two hex digits of their MD5 hashes*. (Two digits might not be enough--you might need three or four. You may also want to use folders, especially if you need more than two digits.) When testing if a string exists, first calculate its MD5 hash and extract the necessary number of digits, then load that file into memory and scan its list. (You can cache these lists in memory so that you only have to load each file once--just make sure that a didReceiveMemoryWarning message will empty those caches.)
Properly configured, SQLite may be faster than the eight second load time you talk about, especially if you ensure it indexes the column you store the strings in. But it's probably overkill for this application.
\* A hash is a numeric code calculated from a string; on average, changing a single bit anywhere in the string should change half the bits in the hash, so even very similar strings should generate very different hashes. I suggest using MD5 instead of -\[NSString hash\] because the hash method is not guaranteed to return the same results on Mac OS and iPhone OS, or on different releases of either OS. You could also use a different algorithm, like a CRC; these are faster but I'm not as familiar with them. This thread discusses calculating MD5 hashes on iPhone OS: http://discussions.apple.com/thread.jspa?messageID=7362074
Message was edited by: Brent Royal-Gordon

Similar Messages

  • How to load a large amount of HTML into HTML region?

    I am trying to display a clickable image map (HTML <map>) in a region. The HTML source for the image map is fairly large and will not fit in the Apex editor (HTTP 400 error when I Apply Changes). I would also rather not manage that much HTML in the Apex web editor. So I stored the code in a file and added it to my applications file storage.
    I have tried various methods of getting the HTML to load when the page is rendered. I tried a URL region, but that leads to all kinds of ACL/security issues that we do not want the customner to have to deal with. i also tried some PL/SQL:
    DECLARE
    l_file_id NUMBER;
    BEGIN
    SELECT id
    INTO l_file_id
    FROM APEX_APPLICATION_FILES
    WHERE filename = 'myhtml';
    APEX_UTIL.GET_FILE(
    p_file_id => l_file_id,
    p_inline => 'YES');
    END;
    But that just replaces the entire page, not just the region it's defined in (even when the HTML is without <head> etc).
    Various attampes wih #APP_IMAGES#myhtml and &APP_IMAGES.myhtml just give me the translation of the APP_IMAGES variable.
    So, how do I load a large chunk of HTML into a region dynamically at run time? I also need this to interact with APEX in the sense that JavaScript will set APEX variables and cause a SUBMIT when the use clicks on the image map.

    Hi Andy,
    ATD wrote:
    Does your HTML define the regions/points on the map using AREA tags?Yes. it is actually generated using MapSefrver from huge tables of SDO_GEOMETRY (Oracle Spatial).
    If so, you could define a report template that does this and use this for a report based on a table that has the settings for shape, coords, href etcHmm, the code (HTML map) is auto-generated so if I understand you correctly, this might be difficult. One of the HTML is approximately 180KB of text.
    I found a way to do this using dynamic PL/SQL. I created a new table that has a varchar filename and a CLOB for the file data. I then imported the HTML into the table using SQL Developer (copy&paste, nice!). I then created an HTML region and used the following:
    declare
    html clob;
    len number;
    st number;
    c number;
    begin
    select length(data)
    into len
    from FILES
    where name = 'state_query.html';
    st := 1;
    while len > 0
    loop
    if len > 32000 then
    c := 32000;
    else
    c := len;
    end if;
    select substr( data,st,c )
    into html
    from FILES
    where name = 'state_query.html';
    htp.p( html );
    st := st + c;
    len := len - c;
    end loop;
    end;
    Edited by: CoyoteTech on May 13, 2009 7:27 AM

  • Trouble loading a large number of csv files

    Hi All,
    I am having an issue loading a large number of csv files into my LabVIEW program. I have attached a png of the simplified code for the load sequence alone.
    What I want to do is load data from 5000 laser beam profiles, so 5000 csv files (68x68 elements), and then carry out some data analysis. However, the program will only ever load 2117 files, and I get no error messages. I have also tried, initially loading a single file, selecting a crop area - say 30x30 elements - and then loading the rest of the files cropped to these dimensions, but I still only get 2117 files.
    Any thoughts would be much appreciated,
    Kevin
    Kevin Conlisk
    Ph.D Student
    National Centre for Laser Applications
    National University of Ireland, Galway
    IRELAND
    Solved!
    Go to Solution.
    Attachments:
    Load csv files.PNG ‏14 KB

    How many elements are in the array of paths (your size(s) indicator) ?
    I suspect that the open file is somewhat limited to a certain number.
    You could also select a certain folder and use 'List Folder' to get a list of files and load those.
    Your data set is 170 MB, not really asthounising, however you should whatc your programming to prevent data-doublures.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Load an existing Berkeley DB file into memory

    Dear Experts,
    I have created some Berkeley DB (BDB) files onto disk.
    I noticed that when I issue key-value retrievals, the page faults are substantial, and the CPU utilization is low.
    One sample of the time command line output is as follow:
    1.36user 1.45system 0:10.83elapsed 26%CPU (0avgtext+0avgdata 723504maxresident)k
    108224inputs+528outputs (581major+76329minor)pagefaults 0swaps
    I suspect that the bottleneck is the high frequency of file I/O.
    This may be because of page faults of the BDB file, and the pages are loaded in/out of disk fairly frequently.
    I wish to explore how to reduce this page fault, and hence expedite the retrieval time.
    One way I have read is to load the entire BDB file into main memory.
    There are some example programs on docs.oracle.com, under the heading "Writing In-Memory Berkeley DB Applications".
    However, I could not get them to work.
    I enclosed below my code:
    --------------- start of code snippets ---------------
    /* Initialize our handles */
    DB *dbp = NULL;
    DB_ENV *envp = NULL;
    DB_MPOOLFILE *mpf = NULL;
    const char *db_name = "db.id_url";   // A BDB file on disk, size  66,813,952
    u_int32_t open_flags;
    /* Create the environment */
    db_env_create(&envp, 0);
    open_flags =
    DB_CREATE | /* Create the environment if it does not exist */
    DB_INIT_LOCK | /* Initialize the locking subsystem */
    DB_INIT_LOG | /* Initialize the logging subsystem */
    DB_INIT_MPOOL | /* Initialize the memory pool (in-memory cache) */
    DB_INIT_TXN |
    DB_PRIVATE; /* Region files are not backed by the filesystem.
    * Instead, they are backed by heap memory. */
    * Specify the size of the in-memory cache.
    envp->set_cachesize(envp, 0, 70 * 1024 * 1024, 1); // 70 Mbytes, more than the BDB file size of 66,813,952
    * Now actually open the environment. Notice that the environment home
    * directory is NULL. This is required for an in-memory only application.
    envp->open(envp, NULL, open_flags, 0);
    /* Open the MPOOL file in the environment. */
    envp->memp_fcreate(envp, &mpf, 0);
    int pagesize = 4096;
    if ((ret = mpf->open(mpf, "db.id_url", 0, 0, pagesize)) != 0) {
    envp->err(envp, ret, "DB_MPOOLFILE->open: ");
    goto err;
    int cnt, hits = 66813952/pagesize;
    void *p=0;
    for (cnt = 0; cnt < hits; ++cnt) {
    db_pgno_t pageno = cnt;
    mpf->get(mpf, &pageno, NULL, 0, &p);
    fprintf(stderr,"\n\nretrieve %5d pages\n",cnt);
    /* Initialize the DB handle */
    db_create(&dbp, envp, 0);
    * Set the database open flags. Autocommit is used because we are
    * transactional.
    open_flags = DB_CREATE | DB_AUTO_COMMIT;
    dbp->open(dbp, // Pointer to the database
    NULL, // Txn pointer
    NULL, // File name -- NULL for inmemory
    db_name, // Logical db name
    DB_BTREE, // Database type (using btree)
    open_flags, // Open flags
    0); // File mode. defaults is 0
    DBT key,data; int test_key=103456;
    memset(&key, 0, sizeof(key));
    memset(&data, 0, sizeof(data));
    key.data = (int*)&test_key;
    key.size = sizeof(test_key);
    dbp->get(dbp, NULL, &key, &data, 0);
    printf("%d --> %s ", *((int*)key.data),(char*)data.data );
    /* Close our database handle, if it was opened. */
    if (dbp != NULL) {
    dbp->close(dbp, 0);
    if (mpf != NULL) (void)mpf->close(mpf, 0);
    /* Close our environment, if it was opened. */
    if (envp != NULL) {
    envp->close(envp, 0);
    /* Final status message and return. */
    printf("I'm all done.\n");
    --------------- end of code snippets ---------------
    After compilation, the code output is:
    retrieve 16312 pages
    103456 --> (null) I'm all done.
    However, the test_key input did not get the correct value retrieval.
    I have been reading and trying this for the past 3 days.
    I will appreciate any help/tips.
    Thank you for your kind attention.
    WAN
    Singapore

    Hi Mike
    Thank you for your 3 steps:
    -- create the database
    -- load the database
    -- run you retrievals
    Recall that my original intention is to load in an existing BDB file (70Mbytes) completely into memory.
    So following your 3 steps above, this is what I did:
    Step-1 (create the database)
    I have followed the oracle article on http://docs.oracle.com/cd/E17076_02/html/articles/inmemory/C/index.html
    In this step, I have created the environment, set the cachesize to be bigger than the BDB file.
    However, I have some problem with the code that opens the DB handle.
    The code on the oracle page is as follow:
    * Open the database. Note that the file name is NULL.
    * This forces the database to be stored in the cache only.
    * Also note that the database has a name, even though its
    * file name is NULL.
    ret = dbp->open(dbp, /* Pointer to the database */
    NULL, /* Txn pointer */
    NULL, /* File name is not specified on purpose */
    db_name, /* Logical db name. */
    DB_BTREE, /* Database type (using btree) */
    db_flags, /* Open flags */
    0); /* File mode. Using defaults */
    Note that the open(..) API does not include the BDB file name.
    The documentation says that this is so that the API will know that it needs an in-memory database.
    However, how do I tell the API the source of the existing BDB file from which I wish to load entirely into memory ?
    Do I need to create another DB handle (non-in-memory, with a file name as argument) that reads from this BDB file, and then call DB->put(.) that inserts the records into the in-memory DB ?
    Step-2 (load the database)
    My question in this step-2 is the same as my last question in step-1, on how do I tell the API to load in my existing BDB file into memory?
    That is, should I create another DB handle (non-in-memory) that reads from the existing BDB file, use a cursor to read in EVERY key-value pair, and then insert into the in-memory DB?
    Am I correct to say that by using the cursor to read in EVERY key-value pair, I am effectively warming the file cache, so that the BDB retrieval performance can be maximized ?
    Step-3 (run your retrievals)
    Are the retrieval API, e.g. c_get(..), get(..), for the in-memory DB, the same as the file-based DB ?
    Thank you and always appreciative for your tips.
    WAN
    Singapore

  • Is there a way of combining a large number of materials into a grouping cod

    Greetings,
    Is there a way of combining a large number of materials into a grouping code, so that and end-user can manage this grouping... adding and removing materials... for auctions?
    The materials will likely span material groups in R/3, and there could be thousands of materials. Shopping cart templates would be cumbersome.
    I was thinking about a special catalog characteristic with defined names to manage the various groups of materials.
    I appreciate any advice... also in awarding points.
    Jessica

    Hi Jessica
    This is my understanding:
    - You want to 'Specially group' materials other than material group. Each special group, may consists of materials from many material groups.
    - User(s) pick materials from this group during 'Auction' creation or 'shopping cart' creation.
    Am I right ?
    Looks like using 'Catalog' is the option.
    - MDM Catalog 'mask' or other Catalogs views to have user specific catalog view
    - Maintenance of this catalog by user could become a problem. Then, you need to give content mgmt rights to user
    Best regards
    Ramki

  • How to save string into memory

    For example...I have some web address stored as string, and i want to write it into memory (just like ctrl+c when you copy some link), so then i can just go to Firefox, and simply ctrl+v to the address bar. Any ideas? Thanks.
    I've add this topic to swing because i want to copy link to memory via right-mouse-click which opens some pop-up menu and there is item called "copy link", but i dont know how to implement this operation..
    Edited by: Lukasito on Nov 11, 2009 8:20 AM

    [http://www.exampledepot.com/egs/java.awt.datatransfer/ToClip.html]

  • How can I copy a large number of contacts into a list in the address book?

    I want to send a message to a large fraction of the people in my address book. How do I copy their addresses into a new list without doing it by hand?

    Thanks for your answer. It works very poorly. I have tried a number of permutations, and each one fails in some way. If I try to copy ten names, it may just write the first few. if I highlight all the names in the source book, then the list name doesn't highlight when I move my cursor over it - only the other address books do that. I got the closest to success by exporting my entire source address book to a text file, removing the unwanted names by hand, and then importing only a few fields to a new address book - name and email address. When I highlight all the entries in this new address book and drag them to the target list, it copies MOST but not all of the entries. I have never seen drag and drop work so poorly. Any ideas?

  • Efficient method to insert large number of data into table

    Hi,
    I have a procedure that accepts an input parameter, that contains, a comma seperated values as input.
    Something like G12-UHG,THA-90HJ,NS-98039,........There can be more than 90,000 values in that comma seperated input paramter.
    What is the most efficient way to do an insert in this case?.
    3 methods I have in mind are :
    1) Get individual tokens from CSV and use a plain old loop and do an insert.
    2) Use BULK COLLECT & FOR ALL. However I don't know how to do this, since input is not from cursor, rather a parameter.
    3) Use Table collections. Again this involves plain old looping through the collection. Same as 1st method.
    Please do suggest the most efficient method.
    Thanks

    90,000 values?? Whats the data type of the input parameter?
    you can use the string to row conversion trick if you want and do a single insert
    SQL> with t as (select 'ABC,DEF GHI,JKL' str from dual)
      2  select regexp_substr(str,'[^,]+', 1, level) list
      3  from t connect by level <= NVL( LENGTH( REGEXP_REPLACE( str, '[^,]+', NULL ) ), 0 ) + 1
      4  /
    LIST
    ABC
    DEF GHI
    JKL Edited by: Karthick_Arp on Feb 13, 2009 2:18 AM

  • Placing a large number of files into separate pages

    Hello,
    Let's say I have 50 pages in an InDesign document and also 50 different eps files in a folder. Can InDesign place these 50 eps files on each page? Thank you.

    The supplied script ImageCatalog will do this. Launch the script, select the folder source, select 1 image per row and 1 per column, and you will have 50 images placed on 50 pages.

  • Huge memory usage while parsing a large number of files

    hi,
    I use ORACLE8i XML parser class in my app.The problem is that
    when I parse a large number of xml files ,memory usage is so
    huge as more than 100M byte.Even worse,sometime I saw virtual
    memory low dialog.Could anybody give me some idea about this.
    any reply are welcome.Thanks a lot.

    Hi Mike. Yes I do have this enabled but this should only be requesting login to view the normal (open) applications. What I end up getting, after I login, is all the applications restarting. In the case of the synchronising files the database has to rebuild itself every time (160,000 files), and nothing has been happening while logged out. Using the Caffeine app I have still enabled the screensaver using a hot corner and had to log back in after 10 minutes but all the applications were still running, including the synchronisation. I am pretty sure my laptop has not gone into sleep mode, or it wouldn't have to reopen the apps, but it also has not shutdown as I get a login box as soon as I press any key. I can't understand the problem, and what makes it even stranger is that it is happening on two separate MacBooks at the same time. Thanks for the suggestion – really appreciated.
    OldGnome - thanks for the suggestion for the other app. I chose Caffeine as this has really good user reviews but the other one doesn't seem to have any, but I might still try it. Again thanks for your help.

  • How to load a large image for display on the Palm PDA

    Hello:
    I have a large image I would like to display on LV for Palm PDA. The documentation states there should be a 64K chunk limitation for VIs to compile on the Palm. Therefore, I decided to break this image up into 2D arrays of less than 64K per subVI. My 3.2 Meg image therefore has about 224 2D array subVIs. My motivation is to somehow use the build array function (with concatenate inputs) to reconstruct the image at runtime. I can compile each 2D array subVI as a test, but my attempt to reassemble and compile is futile. When I try to use the build array with only 8 of these subVIs in a top level VI the compiler complains its still too big of a VI. Using get info, memory for this top level states total ~2
    3K of memory usage.
    So can someone help me with this problem. Is there another way to load this size of an image into memory so I can display it on a picture control?
    BTW, this can build on LV for PocketPC.
    Thank you
    Robert

    Hi Robert,
    You are correct in that one of the limitations of the Palm OS is that files cannot be larger than 64 KB in size (as stated on page 5-3 of the LabVIEW PDA Module User Manual). The suggested workaround is indeed to have a top-level PDA VI that calls subVIs, and this top-level VI can then have a total file size larger than 64 KB.
    My suspicion is that with the picture control on the Palm OS, even if you are breaking up the image into smaller subVIs, the process of building the array to reassemble the picture is still forcing the Palm to allocate memory for each of those 2D array subVIs to place on the top-level VI's picture control
    and thus causing the Palm to complain about not having enough memory. The LabVIEW PDA User Manual also states that "There is a total limit of 64 KB on all front panel array data". Thus, when you are trying to use the build array on the top-level VI, the 64 KB limit on front panel array data is still being exceeded -- even with only 8 of these subVIs.
    The following KnowledgeBase article KB 38EJRHFQ: How Do I Put a Picture or Image on My LabVIEW PDA for Palm Front Panel? states that as a workaround, you can shrink the size of your image by using 4-bit or 1-bit data instead of the standard 8-bit pixmap representation.
    This is really just a limitation of the Palm OS and the fact that there is simply no way of displaying that much front panel information for your picture. Either way, you would need to build up the array of pixels for your bitmap, and for a 3.2 MB image, I don
    't believe there is any way for the Palm OS PDA to display the image in its entire at once.
    Sorry about that...
    Kileen C.
    National Instruments

  • Need to blacklist (block) a large number of domains and email addresses

    I tried to import a large number of domains into a transport rule (new/set-transportrule -name xxx -domainis $csv -quarantine $true). 
    I added a few domains manually and tested to make sure the rule was working.  It was.  Then I ran the cmdlet to import a small number of domains (4).  That also worked.  Then I ran the cmdlet on a large number of domains.  The cmdlet
    worked with no error message (once I got the list of domains well under 4096 bytes).  I waited a day to see if the domains would show up in the rule.  But the imported domains did not show up.
    Is there a better solution to blocking large numbers of domains and email addresses?  Or is the transport rule the only option? 

    Since you do not want to crop your images to a square 1:1 aspect ratio changing the canvas to be square will not make your images square they will retain their Aspect Ratio and  image size will be changer to fit within your 1020 px square. There will be a border or borders on a side or two borders on opposite sides.   You do not need a script because Photoshop ships with a Plug-in script to be used in Actions.   What is good about Plugins is the support Actions.  When you record the action the plug-in during action recording records the setting you use in its dialog into  the actions step.  When the Action is played the Plug-in use the recorded setting an bypasses displaying its dialog. So the Action can be Batch.  The Action you would record would have two  Steps.   Step 1  menu File>Automate>Fit Image... in the Fit Image dialog enter 1020 in the width and height  fields.  Step 2 Canvas size enter 1020 pixels in width and height  not relative leave the anchor point centered it you want even borders on two sides set color to white in the canvas size dialog. You can batch the action.
    The above script will also work. Its squares the document then re-sizes to 1020x1020  the action re-sizes the image to fit with in an area 1020 x 1020 then add any missing canvas. The script like the action only process one image so it would also need to be batched. Record the script into and action and batch the action. As the author wrote. The script re size canvas did not specify an anchor point so the default center anchor point is uses  like the action canvas will be added to two sides.

  • Loading time into memory for a large datastore ?

    Is there some analysis/statistics about what would be the loading time for a timesten data store according to the size of the data store.
    We have a problem with one of our clients where loading of datastore into memory takes a long time. but only certain instances it takes this long.. maximum size for data store is set to be 8GB (64bit AIX with 45GB physical memory), is it something to do with transactions which are not committed?
    Also is it advisable to have multiple smaller datastores or one single large datastore...

    When a TimesTen datastore is loaded into memory it has to go through the following steps. If the datastore was shut down (unloaded from memory) cleanly, then the recovery steps essentially are no-ops; if not then they may take a considerable time:
    1. Allocate appropriately sized shared memory segment from the O/S (on some O/S this can take a significant time if the segment is large)
    2. Read the most recent checkpoint file into the shared memory segment from disk. The time for this step depends on the size of the checkpoint file and the sustained read performance of the storage subsystem; a large datastore, slow disks or a lot of I/O contention on the disks can all slow down this step.
    3. Replay all outstanding transaction log files from the point corresposnding to the checkpoint until the end of the log stream is reached. Then rollback any still open transactions. If there is a very large amount of log data to replay then this can take quite some time. This step is skipped if the datastore was shut down cleanly.
    4. Any indices that would have been modified during the log replay are dropped and rebuilt. If there are many indices, on large tables, that need to be rebuilt then this step can also take some time. This phase can be done in parallel (see the RecoveryThreads DSN attribute).
    Once these 4 steps have been done the datastore is usable, but if recovery had to be done then we will immediately take a checkpoint which will happen in the background.
    As you can see from the above there are several variables and so it is hard to give general metrics. For a clean restart (no recovery) then the time should be very close to size of datastore divided by disk sustained read rate.
    The best ways to minimise restart times are to (a) ensure that checkpoints are occurring frequently enough and (b) ensure that the datastore(s) are always shutdown cleanly before e.g. stopping the TimesTen main daemon or rebooting the machine.
    As to whether it is better to have multiple smaller stores or one large one - that depends on several factors.
    - A single large datastore may be more convenient for the application (since all the data is in one place). If the data is split across multiple datastores then transactions cannot span the datastores and if cross-datastorestore queries/joins are needed they must be coded in the application.
    - Smaller datastores can be loaded/unloaded/recovered faster than larger datastores but the increased number of datastores could make system management more complex and/or error prone.
    - For very intensive workloads (especially write workloads) on large SMP machines overall better throughput and scalability will be seen from multiple small datastores compared to a single large datastore.
    I hope that helps.
    Chris

  • Read a file without loading it into memory

    I have a VERY large file filled with words. I want to determine if a String in my program matches one of them. Loading the entire file into memory would take a long time and would use way too much memory. Is there some way to load just the part I need each time or make the comparison directly from the file on the hard disk?

    The file is static, so your plan seems to have merit.
    I've only used sequential files before, but I'm
    assuming this would require a random access file since
    you have to begin reading at a specified offset. Am I
    correct?Yes.
    In addition, if this file is fixed-length "records" so that you could programmatically determine the word offsets without having to keep a map of indexes in memory, you could just employ a search algorithm (I forget what this one is called) - you could start by defining 2 endpoints, initially at offset 0 and the offset of the last word.
    Iteratively read the word halfway between the 2 endpoints, adjusting the endpoints until a match is found or the endpoints converge.

  • How to load a BDB file into memory?

    The entire BDB database needs to reside in memory for performance reasons, it needs to be in memory all the time, not paged in on demand. The physical memory and virtual process address space are large enough to hold this file. How can I load it into memory just before accessing the first entry? I've read the C++ API reference, and it seems that I can do the following:
    1, Create a DB environment;
    2, Call DB_ENV->set_cachesize() to set a memory pool large enough to hold the BDB file;
    3, Call DB_MPOOLFILE->open() to open the BDB file in memory pool of that DB environment;
    4, Create a DB handle in that DB environment and open the BDB file (again) via this DB handle.
    My questions are:
    1, Is there a more elegant way instead of using that DB environment? If the DB environment is a must, then:
    2, Does step 3 above load the BDB file into memory pool or just reserve enough space for that file?
    Thanks in advance,
    Feng

    Hello,
    Does the documentation on "Memory-only or Flash configurations" at:
    http://download.oracle.com/docs/cd/E17076_02/html/programmer_reference/program_ram.html
    answer the question?
    From there we have:
    By default, databases are periodically flushed from the Berkeley DB memory cache to backing physical files in the filesystem. To keep databases from being written to backing physical files, pass the DB_MPOOL_NOFILE flag to the DB_MPOOLFILE->set_flags() method. This flag implies the application's databases must fit entirely in the Berkeley DB cache, of course. To avoid a database file growing to consume the entire cache, applications can limit the size of individual databases in the cache by calling the DB_MPOOLFILE->set_maxsize() method.
    Thanks,
    Sandra

Maybe you are looking for