当前位置: 首页>>代码示例>>C++>>正文


C++ DataObjectRef::calcId方法代码示例

本文整理汇总了C++中DataObjectRef::calcId方法的典型用法代码示例。如果您正苦于以下问题:C++ DataObjectRef::calcId方法的具体用法?C++ DataObjectRef::calcId怎么用?C++ DataObjectRef::calcId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataObjectRef的用法示例。


在下文中一共展示了DataObjectRef::calcId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

/**
* selfTest() depends upon periodic purging.   Every call, it will first fill up the database, taking memory snapshots,
* then purge, taking more memory snapshots.   It creates a number of random data objects, inserts them into the system,
* and records current memory usage into a file called 'mem.results', for every interation.   It does in the following steps:
*
* 1.  Add, approximately, 20 DO's per second, done every poll period (e.g. 10 seconds, means add 200 for that interval).
*
* 2.  When the number of DO's in the system match the threshold setting, we drop the threshold by the same number
* we increased it in step 1.   In this case, we decrease it by 20, allowing the memory threshold purger to do its job.
*
* 3.  Repeat step 1.
*
* 4.  Repeat step 2.
*
* 5.  Reset system functions to original defaults.
*
* This allows the system to approach maximum usage, drop to zero, back to maximum usage, then back to zero.
* The file can be parse into a plot showing how much memory is freed.   This test works regardless of using
* in memory database, the improved all memory database, or disk based database.
* 
* WARNING: We use mallinfo() to determine the amount of memory used and released, as the system does NOT
* see any memory freed at all, due to the fact dlmallopt(-1) is set in main.cpp.  This tells free to not
* return freed memory to the system.    Thus, using mallinfo is the only means available to show how much
* memory is actually freed to the application (but not to the system).
* 
*  
*/
void
CacheStrategyUtility::selfTest()
{
    static int init=0;
    static float amount_do=0;
    static int count=0;
    char countStr[50];
    static float threshold_backup;
    static char *direction;
    if (!init) {
       init=1;
       threshold_backup=db_size_threshold;
       amount_do=20.0*pollPeriodMs/1000; //20 per second seems reasonable
       if (amount_do > db_size_threshold/10) {
         amount_do = db_size_threshold/10;
       }
       direction="Start";

    }   // JM: Start DB purging
        // JM: Testing code only, to prove it works.   Lets do linear testing.
        struct mallinfo mi=mallinfo();
	//Due to file permission difficulties in android, we'll write it as a log
        HAGGLE_DBG("\nThreshold(%s): %lld/%d -- Used bytes: %d, Free bytes: %d, SQL: %lld\n\n", direction, db_size_threshold,current_num_do, mi.uordblks, mi.fordblks, sqlite3_memory_used());
        //send db_size_threshold DO's
	//init = 1 means send DO's
	//init = 2 means we are in purging mode
        if ((init == 1) || (init == 3)) {
          float upperlimit=current_num_do+amount_do;
          if (upperlimit > db_size_threshold) {
            upperlimit = db_size_threshold+1;
	    init++;
          }
          if (init ==1) {
             direction="Up1";
          } else if (init == 3) {
             direction="Up2";
          } else { 
             direction="StateChangeFromUp";
          }

          for(int i=current_num_do; i<upperlimit; i++) {
	    DataObjectRef dObj = createDataObject(2);
	    dObj->addAttribute("ContentOriginator", "self");
	    dObj->addAttribute("ContentType", "DelByRelTTL");
	    dObj->addAttribute("ContentType2", "DelByAbsTTL");
	    dObj->addAttribute("purge_by_timestamp", "2000000000");
	    dObj->addAttribute("purge_after_seconds", "2000000000");
            char buffer[1025];
            snprintf(buffer, 1024, "%llu", (unsigned long long)time(NULL));
            sprintf(countStr, "%d", count++);
	    dObj->addAttribute("ContentCreationTime", buffer);
	    dObj->addAttribute("count", countStr);
            dObj->calcId();
	    _handleNewDataObject(dObj);
          }
         } else if ((init == 2) || (init == 4)) {   //init==2, reduction
            db_size_threshold -= amount_do;
            if (db_size_threshold < 0.0) {
              init++;
              db_size_threshold=threshold_backup;
            }
            if (init == 2) {
               direction="Down1";
            } else if (init == 4) {
               direction="Down2";
            } else {
               direction="StateChangeFromDown";
            }
         } else { //if (init == 5) 
           //clear seltTest?
           self_test = false;
           db_size_threshold=threshold_backup;
           HAGGLE_DBG("Self Test completed!\n");
//.........这里部分代码省略.........
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:101,代码来源:CacheStrategyUtility.cpp


注:本文中的DataObjectRef::calcId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。