"inmem" through ged

Help
Tobias
2013-05-13
2013-05-23
  • Tobias
    Tobias
    2013-05-13

    Hi,

    I am discovering brl-cad and would like to put all data, which brl-cad-mged works on, onto the heap "inmem".

    My understanding of inmem is, that no files will be saved on the filesystem. Therefore all operations and calculations will be done based on data laying "in memory". Hence I can decide what goes through the bottleneck HDD.

    The ged interface provides the ged_open function ( in ged.c ). This function takes as dbtype "inmem" and as a filename "0" (pointer address as a string).
    The nullpointer given to that function will make it allocate a db_i.

    When calling ged_in( IN command )
    the error message: "rt_db_put_internal5(box) db_realloc5() failed" is thrown.

    My guess is, when a directory is created by db_diradd() in the ged_in() function (in typein.c), the RT_DIR_INMEM flag at (directory).flags is not set and the (directory).d_un->ptr is not set to null ( no allocated memory yet).

    So what is happening? Do I have to prepare the database for being an inmemory database?
    How do I prepare the database for in memory use?
    Can I use it then "normal" with ged_in etc... ?

    Cheers,
    Tobias

     
    • Sean Morrison
      Sean Morrison
      2013-05-13

      Hi Tobias,

      On May 13, 2013, at 3:57 AM, Tobias wrote:

      I am discovering brl-cad and would like to put all data, which brl-cad-mged works on, onto the heap "inmem".

      My understanding of inmem is, that no files will be saved on the filesystem. Therefore all operations and calculations will be done based on data laying "in memory". Hence I can decide what goes through the bottleneck HDD.

      Your understanding sounds right.

      The ged interface provides the ged_open function ( in ged.c ). This function takes as dbtype "inmem" and as a filename "0" (pointer address as a string).
      The nullpointer given to that function will make it allocate a db_i.

      When calling ged_in( IN command )
      the error message: "rt_db_put_internal5(box) db_realloc5() failed" is thrown.

      There's a variety of reasons rt_db_put_internal5() might fail such as a read-only or uninitialized database context. Can you provide the sample code you have that demonstrates this problem?

      Some of the ged_() functions might not be "inmem-safe" simply because they've not been tested as thoroughly. The underlying rt_() functions should be safe, but again it gets back to what exactly is the code you've got and we can go from there.

      Cheers!
      Sean

       
  • Sean Morrison
    Sean Morrison
    2013-05-13

    That totally did not quote correctly. My responses interleaved were:

    Your understanding sounds right. There's a variety of reasons rt_db_put_internal5() might fail such as a read-only or uninitialized database context. Can you provide the sample code you have that demonstrates this problem? Some of the ged_() functions might not be "inmem-safe" simply because they've not been tested as thoroughly. The underlying rt_() functions should be safe, but again it gets back to what exactly is the code you've got and we can go from there.

    Cheers!
    Sean

     
    • Tobias
      Tobias
      2013-05-14

      Thank you for answer.

                 const char* sDbType = "db"; // there is "db" "file"
          const char* box[15];
          box[0] = "in";
          box[1] = "box";
          box[2] = "box";
          box[3] = "0";
          box[4] = "0";
          box[5] = "0";
          box[6] = "0";
          box[7] = "0";
          box[8] = "1";
          box[9] = "0";
          box[10] = "1";
          box[11] = "0";
          box[12] = "1";
          box[13] = "0";
          box[14] = "0";
      
          //call to open a ged with type name and (exisitng only) false
          ged* gedHdd = ged_open(sDbType, "box.g", false);
          ged_in(gedHdd, 15, box);
          ged_close(gedHdd);
      
          /* DOTHE SAME INMEM */
          const char *inmemType = "inmem";
      
          ged* gedMem = ged_open(inmemType, "0x0", false);
          int status = ged_in(gedMem, 15, box);
      
          if (status == GED_ERROR)
              std::cout<<(gedMem->ged_result_str->vls_str)<<std::endl;
          ged_close (gedMem);
      

      I call the ged created inmem.

      Are the db_ functions inmem proof? Because the db_diradd seems to be the root of the problem. Because the d_un->ptr will be set to 0xfff.... a check for Null results in a reallocation. Therefore the reallocation error is thrown.

      Is there somewhere a documentation which shows how a inmem database should be handled?

      Cheers,
      Tobias

       
  • Tobias
    Tobias
    2013-05-21

    Hi,

    I found a solution, which enables inmem databases using trough the ged tool.

    The rt_db_put_internal functions converts an internal representation into an external representation and "attaches" it to a database/ the representation of a database.
    I changed:
    Checking the database type and if it is "inmem"

    • Converting the internal representation into an external one
    • Let the external representation be stolen by db_inmem. And setting the flag for an inmemory representation.

    Basically this is the implementation from the db_inmem.c description.

    I would like to contribute those changes. How am I able to do that?

    Cheers,
    Tobias

     
    • Sean Morrison
      Sean Morrison
      2013-05-23

      On May 21, 2013, at 11:18 AM, Tobias cucu001@users.sf.net wrote:

      Hi,
      I found a solution, which enables inmem databases using trough the ged tool.

      Hi Tobias, awesome that you found a solution.  Hadn't been able to debug your case yet due to release preparations that are under way, but hadn't forgotten.

      The rt_db_put_internal functions converts an internal representation into an external representation and "attaches" it to a database/ the representation of a database.
      I changed:
      Checking the database type and if it is "inmem"
      Converting the internal representation into an external one
      Let the external representation be stolen by db_inmem. And setting the flag for an inmemory representation.
      Basically this is the implementation from the db_inmem.c description.
      I would like to contribute those changes. How am I able to do that?

      The starting point for any new contributor is usually to read the HACKING file in a source checkout, make a patch that conforms to our coding style, and submit that to our patches tracker on sourceforge.  Links and more info are in the HACKING file.

      The smaller and simpler the patch, the better actually.  That's not the way we want to interact with you, it's just to demonstrate you understand our conventions and then get you committing directly eventually.

      Cheers!
      Sean