您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ sqlite3Malloc函数代码示例

51自学网 2021-06-03 08:14:17
  C++
这篇教程C++ sqlite3Malloc函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中sqlite3Malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ sqlite3Malloc函数的具体用法?C++ sqlite3Malloc怎么用?C++ sqlite3Malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

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

示例1: assert

/* Insert an element into the hash table pH.  The key is pKey,nKey** and the data is "data".**** If no element exists with a matching key, then a new** element is created.  A copy of the key is made if the copyKey** flag is set.  NULL is returned.**** If another element already exists with the same key, then the** new data replaces the old data and the old data is returned.** The key is not copied in this instance.  If a malloc fails, then** the new data is returned and the hash table is unchanged.**** If the "data" parameter to this function is NULL, then the** element corresponding to "key" is removed from the hash table.*/void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){  int hraw;             /* Raw hash value of the key */  int h;                /* the hash of the key modulo hash table size */  HashElem *elem;       /* Used to loop thru the element list */  HashElem *new_elem;   /* New element added to the pH */  assert( pH!=0 );  hraw = strHash(pKey, nKey);  if( pH->htsize ){    h = hraw % pH->htsize;    elem = findElementGivenHash(pH,pKey,nKey,h);    if( elem ){      void *old_data = elem->data;      if( data==0 ){        removeElementGivenHash(pH,elem,h);      }else{        elem->data = data;        if( !pH->copyKey ){          elem->pKey = (void *)pKey;        }        assert(nKey==elem->nKey);      }      return old_data;    }  }  if( data==0 ) return 0;  new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );  if( new_elem==0 ) return data;  if( pH->copyKey && pKey!=0 ){    new_elem->pKey = sqlite3Malloc( nKey );    if( new_elem->pKey==0 ){      sqlite3_free(new_elem);      return data;    }    memcpy((void*)new_elem->pKey, pKey, nKey);  }else{    new_elem->pKey = (void*)pKey;  }  new_elem->nKey = nKey;  pH->count++;  if( pH->htsize==0 ){    rehash(pH, 128/sizeof(pH->ht[0]));    if( pH->htsize==0 ){      pH->count = 0;      if( pH->copyKey ){        sqlite3_free(new_elem->pKey);      }      sqlite3_free(new_elem);      return data;    }  }  if( pH->count > pH->htsize ){    rehash(pH,pH->htsize*2);  }  assert( pH->htsize>0 );  h = hraw % pH->htsize;  insertElement(pH, &pH->ht[h], new_elem);  new_elem->data = data;  return 0;}
开发者ID:kfengbest,项目名称:GenericDB,代码行数:75,


示例2: cipher_ctx_init

/**  * Initialize a a new cipher_ctx struct. This function will allocate memory  * for the cipher context and for the key  *   * returns SQLITE_OK if initialization was successful  * returns SQLITE_NOMEM if an error occured allocating memory  */static int cipher_ctx_init(cipher_ctx **iCtx) {  cipher_ctx *ctx;  *iCtx = sqlite3Malloc(sizeof(cipher_ctx));  ctx = *iCtx;  if(ctx == NULL) return SQLITE_NOMEM;  memset(ctx, 0, sizeof(cipher_ctx));   ctx->key = sqlite3Malloc(EVP_MAX_KEY_LENGTH);  if(ctx->key == NULL) return SQLITE_NOMEM;  return SQLITE_OK;}
开发者ID:TheDleo,项目名称:ocRosa,代码行数:17,


示例3: sqlite3CodecAttach

int sqlite3CodecAttach(sqlite3* db, int nDb, const void *zKey, int nKey) {  struct Db *pDb = &db->aDb[nDb];    if(nKey && zKey && pDb->pBt) {    codec_ctx *ctx;    Pager *pPager = pDb->pBt->pBt->pPager;    int prepared_key_sz;    ctx = sqlite3Malloc(sizeof(codec_ctx));    if(ctx == NULL) return SQLITE_NOMEM;    memset(ctx, 0, sizeof(codec_ctx)); /* initialize all pointers and values to 0 */     ctx->pBt = pDb->pBt; /* assign pointer to database btree structure */        /* pre-allocate a page buffer of PageSize bytes. This will       be used as a persistent buffer for encryption and decryption        operations to avoid overhead of multiple memory allocations*/    ctx->buffer = sqlite3Malloc(sqlite3BtreeGetPageSize(ctx->pBt));    if(ctx->buffer == NULL) return SQLITE_NOMEM;           ctx->key_sz = EVP_CIPHER_key_length(CIPHER);    ctx->iv_sz = EVP_CIPHER_iv_length(CIPHER);        /* allocate space for salt data */    ctx->salt = sqlite3Malloc(FILE_HEADER_SZ);    if(ctx->salt == NULL) return SQLITE_NOMEM;        /* allocate space for salt data */    ctx->key = sqlite3Malloc(ctx->key_sz);    if(ctx->key == NULL) return SQLITE_NOMEM;       /* allocate space for raw key data */    ctx->pass = sqlite3Malloc(nKey);    if(ctx->pass == NULL) return SQLITE_NOMEM;    memcpy(ctx->pass, zKey, nKey);    ctx->pass_sz = nKey;    /* read the first 16 bytes directly off the database file. This is the salt. */    sqlite3_file *fd = sqlite3Pager_get_fd(pPager);    if(fd == NULL || sqlite3OsRead(fd, ctx->salt, 16, 0) != SQLITE_OK) {      /* if unable to read the bytes, generate random salt */      RAND_pseudo_bytes(ctx->salt, FILE_HEADER_SZ);    }        codec_prepare_key(db, zKey, nKey, ctx->salt, FILE_HEADER_SZ, ctx->key, &prepared_key_sz);    assert(prepared_key_sz == ctx->key_sz);        sqlite3BtreeSetPageSize(ctx->pBt, sqlite3BtreeGetPageSize(ctx->pBt), ctx->iv_sz, 0);    sqlite3PagerSetCodec(sqlite3BtreePager(pDb->pBt), sqlite3Codec, (void *) ctx);    return SQLITE_OK;  }  return SQLITE_ERROR;}
开发者ID:qianwang,项目名称:sqlcipher,代码行数:53,


示例4: assert

/*** Allocate and zero memory.  If the allocation fails, make** the mallocFailed flag in the connection pointer.**** If db!=0 and db->mallocFailed is true (indicating a prior malloc** failure on the same database connection) then always return 0.** Hence for a particular database connection, once malloc starts** failing, it fails consistently until mallocFailed is reset.** This is an important assumption.  There are many places in the** code that do things like this:****         int *a = (int*)sqlite3DbMallocRaw(db, 100);**         int *b = (int*)sqlite3DbMallocRaw(db, 200);**         if( b ) a[10] = 9;**** In other words, if a subsequent malloc (ex: "b") worked, it is assumed** that all prior mallocs (ex: "a") worked too.*/void *sqlite3DbMallocRaw(sqlite3 *db, int n){  void *p;  assert( db==0 || sqlite3_mutex_held(db->mutex) );#ifndef SQLITE_OMIT_LOOKASIDE  if( db ){    LookasideSlot *pBuf;    if( db->mallocFailed ){      return 0;    }    if( db->lookaside.bEnabled && n<=db->lookaside.sz         && (pBuf = db->lookaside.pFree)!=0 ){      db->lookaside.pFree = pBuf->pNext;      db->lookaside.nOut++;      if( db->lookaside.nOut>db->lookaside.mxOut ){        db->lookaside.mxOut = db->lookaside.nOut;      }      return (void*)pBuf;    }  }#else  if( db && db->mallocFailed ){    return 0;  }#endif  p = sqlite3Malloc(n);  if( !p && db ){    db->mallocFailed = 1;  }  sqlite3MemdebugSetType(p,            (db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);  return p;}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:50,


示例5: testAppend

void testAppend(){		OsFile id;/* I don't like the implementation since OSFile need to create by myself*/	int Readonly;	int i,nPages;	double time;		char * buf=sqlite3Malloc(config.pagesize);	rc = sqlite3OsOpenReadWrite( config.datfile, &id, &Readonly);	errorHandle(rc, "can't open the file");	for(nPages=1; nPages<=config.pagenum; nPages++){				printf("append %d pages!/n",nPages);						start_timer();		for(i=0;i<nPages;i++){			sqlite3Randomness(config.pagesize, buf);			rc = sqlite3OsWrite(&id, buf, config.pagesize);			errorHandle(rc, "write error");		}		time = get_timer();		pr_times(config.recordfile, time);					}	rc= sqlite3OsClose(&id);	errorHandle(rc, "can't close the file");    //TODO can't find the defintion, do it later    //sqlite3Free((void *)buf);}
开发者ID:SValeriu,项目名称:sqlite-btree,代码行数:34,


示例6: sqlite3ThreadCreate

/* Create a new thread */int sqlite3ThreadCreate(  SQLiteThread **ppThread,  /* OUT: Write the thread object here */  void *(*xTask)(void*),    /* Routine to run in a separate thread */  void *pIn                 /* Argument passed into xTask() */){  SQLiteThread *p;  int rc;  assert( ppThread!=0 );  assert( xTask!=0 );  /* This routine is never used in single-threaded mode */  assert( sqlite3GlobalConfig.bCoreMutex!=0 );  *ppThread = 0;  p = sqlite3Malloc(sizeof(*p));  if( p==0 ) return SQLITE_NOMEM_BKPT;  memset(p, 0, sizeof(*p));  p->xTask = xTask;  p->pIn = pIn;  /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a   ** function that returns SQLITE_ERROR when passed the argument 200, that  ** forces worker threads to run sequentially and deterministically   ** for testing purposes. */  if( sqlite3FaultSim(200) ){    rc = 1;  }else{        rc = pthread_create(&p->tid, 0, xTask, pIn);  }  if( rc ){    p->done = 1;    p->pOut = xTask(pIn);  }  *ppThread = p;  return SQLITE_OK;}
开发者ID:1018824313,项目名称:sqlite,代码行数:36,


示例7: return

/*** Allocate and zero memory.  If the allocation fails, make** the mallocFailed flag in the connection pointer.**** If db!=0 and db->mallocFailed is true (indicating a prior malloc** failure on the same database connection) then always return 0.** Hence for a particular database connection, once malloc starts** failing, it fails consistently until mallocFailed is reset.** This is an important assumption.  There are many places in the** code that do things like this:****         int *a = (int*)sqlite3DbMallocRaw(db, 100);**         int *b = (int*)sqlite3DbMallocRaw(db, 200);**         if( b ) a[10] = 9;**** In other words, if a subsequent malloc (ex: "b") worked, it is assumed** that all prior mallocs (ex: "a") worked too.*/void *sqlite3DbMallocRaw(sqlite3 *db, int n){  void *p;#ifndef SQLITE_OMIT_LOOKASIDE  if( db ){    LookasideSlot *pBuf;    if( db->mallocFailed ){      return 0;    }    if( db->lookaside.bEnabled && n<=db->lookaside.sz         && (pBuf = db->lookaside.pFree)!=0 ){      db->lookaside.pFree = pBuf->pNext;      db->lookaside.nOut++;      if( db->lookaside.nOut>db->lookaside.mxOut ){        db->lookaside.mxOut = db->lookaside.nOut;      }      return (void*)pBuf;    }  }#else  if( db && db->mallocFailed ){    return 0;  }#endif  p = sqlite3Malloc(n);  if( !p && db ){    db->mallocFailed = 1;  }  return p;}
开发者ID:erik-knudsen,项目名称:eCos-enhancements,代码行数:47,


示例8: assert

/*** Malloc function used within this file to allocate space from the buffer** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no** such buffer exists or there is no space left in it, this function falls** back to sqlite3Malloc().**** Multiple threads can run this routine at the same time.  Global variables** in pcache1 need to be protected via mutex.*/static void *pcache1Alloc(int nByte){  void *p = 0;  assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );  if( nByte<=pcache1.szSlot ){    sqlite3_mutex_enter(pcache1.mutex);    p = (PgHdr1 *)pcache1.pFree;    if( p ){      pcache1.pFree = pcache1.pFree->pNext;      pcache1.nFreeSlot--;      pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;      assert( pcache1.nFreeSlot>=0 );      sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte);      sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1);    }    sqlite3_mutex_leave(pcache1.mutex);  }  if( p==0 ){    /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool.  Get    ** it from sqlite3Malloc instead.    */    p = sqlite3Malloc(nByte);#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS    if( p ){      int sz = sqlite3MallocSize(p);      sqlite3_mutex_enter(pcache1.mutex);      sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte);      sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);      sqlite3_mutex_leave(pcache1.mutex);    }#endif    sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);  }  return p;}
开发者ID:arizwanp,项目名称:intel_sgx,代码行数:43,


示例9: assert

/*** Allocate a page cache line.  Look in the page cache memory pool first** and use an element from it first if available.  If nothing is available** in the page cache memory pool, go to the general purpose memory allocator.*/static void *pcacheMalloc(int sz, PCache *pCache){  assert( sqlite3_mutex_held(pcache_g.mutex) );  if( sz<=pcache_g.szSlot && pcache_g.pFree ){    PgFreeslot *p = pcache_g.pFree;    pcache_g.pFree = p->pNext;    sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, sz);    sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);    return (void*)p;  }else{    void *p;    /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the    ** global pcache mutex and unlock the pager-cache object pCache. This is     ** so that if the attempt to allocate a new buffer causes the the     ** configured soft-heap-limit to be breached, it will be possible to    ** reclaim memory from this pager-cache.    */    pcacheExitMutex();    p = sqlite3Malloc(sz);    pcacheEnterMutex();    if( p ){      sz = sqlite3MallocSize(p);      sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);    }    return p;  }}
开发者ID:contextlogger,项目名称:contextlogger2,代码行数:33,


示例10: switch

/*** The sqlite3_mutex_alloc() routine allocates a new** mutex and returns a pointer to it.  If it returns NULL** that means that a mutex could not be allocated. */static sqlite3_mutex *debugMutexAlloc(int id){  static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_APP3 - 1];  sqlite3_debug_mutex *pNew = 0;  switch( id ){    case SQLITE_MUTEX_FAST:    case SQLITE_MUTEX_RECURSIVE: {      pNew = sqlite3Malloc(sizeof(*pNew));      if( pNew ){        pNew->id = id;        pNew->cnt = 0;      }      break;    }    default: {#ifdef SQLITE_ENABLE_API_ARMOR      if( id-2<0 || id-2>=ArraySize(aStatic) ){        (void)SQLITE_MISUSE_BKPT;        return 0;      }#endif      pNew = &aStatic[id-2];      pNew->id = id;      break;    }  }  return (sqlite3_mutex*)pNew;}
开发者ID:13028122862,项目名称:firefox-ios,代码行数:32,


示例11: assert

/*** Malloc function used within this file to allocate space from the buffer** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no ** such buffer exists or there is no space left in it, this function falls ** back to sqlite3Malloc().*/static void *pcache1Alloc(int nByte){  void *p;  assert( sqlite3_mutex_held(pcache1.mutex) );  if( nByte<=pcache1.szSlot && pcache1.pFree ){    assert( pcache1.isInit );    p = (PgHdr1 *)pcache1.pFree;    pcache1.pFree = pcache1.pFree->pNext;    sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);    sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);  }else{    /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the    ** global pcache mutex and unlock the pager-cache object pCache. This is     ** so that if the attempt to allocate a new buffer causes the the     ** configured soft-heap-limit to be breached, it will be possible to    ** reclaim memory from this pager-cache.    */    pcache1LeaveMutex();    p = sqlite3Malloc(nByte);    pcache1EnterMutex();    if( p ){      int sz = sqlite3MallocSize(p);      sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);    }  }  return p;}
开发者ID:Ramananda,项目名称:sqlcipher,代码行数:33,


示例12: pcache1InitBulk

/*** Try to initialize the pCache->pFree and pCache->pBulk fields.  Return** true if pCache->pFree ends up containing one or more free pages.*/static int pcache1InitBulk(PCache1 *pCache){  i64 szBulk;  char *zBulk;  if( pcache1.nInitPage==0 ) return 0;  /* Do not bother with a bulk allocation if the cache size very small */  if( pCache->nMax<3 ) return 0;  sqlite3BeginBenignMalloc();  if( pcache1.nInitPage>0 ){    szBulk = pCache->szAlloc * (i64)pcache1.nInitPage;  }else{    szBulk = -1024 * (i64)pcache1.nInitPage;  }  if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){    szBulk = pCache->szAlloc*pCache->nMax;  }  zBulk = pCache->pBulk = sqlite3Malloc( szBulk );  sqlite3EndBenignMalloc();  if( zBulk ){    int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;    int i;    for(i=0; i<nBulk; i++){      PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];      pX->page.pBuf = zBulk;      pX->page.pExtra = &pX[1];      pX->isBulkLocal = 1;      pX->isAnchor = 0;      pX->pNext = pCache->pFree;      pCache->pFree = pX;      zBulk += pCache->szAlloc;    }  }  return pCache->pFree!=0;}
开发者ID:arizwanp,项目名称:intel_sgx,代码行数:37,


示例13: rehash

/* Resize the hash table so that it cantains "new_size" buckets.**** The hash table might fail to resize if sqlite3_malloc() fails or** if the new size is the same as the prior size.** Return TRUE if the resize occurs and false if not.*/static int rehash(Hash *pH, unsigned int new_size){  struct _ht *new_ht;            /* The new hash table */  HashElem *elem, *next_elem;    /* For looping over existing elements */#if SQLITE_MALLOC_SOFT_LIMIT>0  if( new_size*sizeof(struct _ht)>SQLITE_MALLOC_SOFT_LIMIT ){    new_size = SQLITE_MALLOC_SOFT_LIMIT/sizeof(struct _ht);  }  if( new_size==pH->htsize ) return 0;#endif  /* The inability to allocates space for a larger hash table is  ** a performance hit but it is not a fatal error.  So mark the  ** allocation as a benign.  */  sqlite3BeginBenignMalloc();  new_ht = (struct _ht *)sqlite3Malloc( new_size*sizeof(struct _ht) );  sqlite3EndBenignMalloc();  if( new_ht==0 ) return 0;  sqlite3_free(pH->ht);  pH->ht = new_ht;  pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);  memset(new_ht, 0, new_size*sizeof(struct _ht));  for(elem=pH->first, pH->first=0; elem; elem = next_elem){    unsigned int h = strHash(elem->pKey, elem->nKey) % new_size;    next_elem = elem->next;    insertElement(pH, &new_ht[h], elem);  }  return 1;}
开发者ID:77songsong,项目名称:sqlite3,代码行数:37,


示例14: assert

/*** Allocate a new page object initially associated with cache pCache.*/static PgHdr1 *pcache1AllocPage(PCache1 *pCache){  PgHdr1 *p = 0;  void *pPg;  /* The group mutex must be released before pcache1Alloc() is called. This  ** is because it may call sqlite3_release_memory(), which assumes that   ** this mutex is not held. */  assert( sqlite3_mutex_held(pCache->pGroup->mutex) );  pcache1LeaveMutex(pCache->pGroup);#ifdef SQLITE_PCACHE_SEPARATE_HEADER  pPg = pcache1Alloc(pCache->szPage);  p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);  if( !pPg || !p ){    pcache1Free(pPg);    sqlite3_free(p);    pPg = 0;  }#else  pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);  p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];#endif  pcache1EnterMutex(pCache->pGroup);  if( pPg ){    p->page.pBuf = pPg;    p->page.pExtra = &p[1];    if( pCache->bPurgeable ){      pCache->pGroup->nCurrentPage++;    }    return p;  }  return 0;}
开发者ID:HuiLi,项目名称:Sqlite3.07.14,代码行数:36,


示例15: sqlite3Malloc

/*** Allocate and zero memory.*/ void *sqlite3MallocZero(u64 n){  void *p = sqlite3Malloc(n);  if( p ){    memset(p, 0, (size_t)n);  }  return p;}
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:10,


示例16: pcacheResizeHash

/*** Attempt to increase the size the hash table to contain** at least nHash buckets.*/static int pcacheResizeHash(PCache *pCache, int nHash){  PgHdr *p;  PgHdr **pNew;  assert( pcacheMutexHeld() );#ifdef SQLITE_MALLOC_SOFT_LIMIT  if( nHash*sizeof(PgHdr*)>SQLITE_MALLOC_SOFT_LIMIT ){    nHash = SQLITE_MALLOC_SOFT_LIMIT/sizeof(PgHdr *);  }#endif  pcacheExitMutex();  pNew = (PgHdr **)sqlite3Malloc(sizeof(PgHdr*)*nHash);  pcacheEnterMutex();  if( !pNew ){    return SQLITE_NOMEM;  }  memset(pNew, 0, sizeof(PgHdr *)*nHash);  sqlite3_free(pCache->apHash);  pCache->apHash = pNew;  pCache->nHash = nHash;  pCache->nPage = 0;   for(p=pCache->pClean; p; p=p->pNext){    pcacheAddToHash(p);  }  for(p=pCache->pDirty; p; p=p->pNext){    pcacheAddToHash(p);  }  return SQLITE_OK;}
开发者ID:contextlogger,项目名称:contextlogger2,代码行数:33,


示例17: sqlite3ThreadCreate

/* Create a new thread */int sqlite3ThreadCreate(  SQLiteThread **ppThread,  /* OUT: Write the thread object here */  void *(*xTask)(void*),    /* Routine to run in a separate thread */  void *pIn                 /* Argument passed into xTask() */){  SQLiteThread *p;  int rc;  assert( ppThread!=0 );  assert( xTask!=0 );  /* This routine is never used in single-threaded mode */  assert( sqlite3GlobalConfig.bCoreMutex!=0 );  *ppThread = 0;  p = sqlite3Malloc(sizeof(*p));  if( p==0 ) return SQLITE_NOMEM;  memset(p, 0, sizeof(*p));  p->xTask = xTask;  p->pIn = pIn;  if( sqlite3FaultSim(200) ){    rc = 1;  }else{        rc = pthread_create(&p->tid, 0, xTask, pIn);  }  if( rc ){    p->done = 1;    p->pOut = xTask(pIn);  }  *ppThread = p;  return SQLITE_OK;}
开发者ID:AchironOS,项目名称:chromium-2,代码行数:32,


示例18: sqlite3Malloc

/*** Allocate and zero memory.*/ void *sqlite3MallocZero(int n){  void *p = sqlite3Malloc(n);  if( p ){    memset(p, 0, n);  }  return p;}
开发者ID:AdrianHuang,项目名称:rt-thread-for-vmm,代码行数:10,


示例19: rehash

/* Resize the hash table so that it cantains "new_size" buckets.**** The hash table might fail to resize if sqlite3_malloc() fails or** if the new size is the same as the prior size.** Return TRUE if the resize occurs and false if not.*/static int rehash(Hash *pH, unsigned int new_size){  struct _ht *new_ht;            /* The new hash table */  HashElem *elem, *next_elem;    /* For looping over existing elements */#if SQLITE_MALLOC_SOFT_LIMIT>0  if( new_size*sizeof(struct _ht)>SQLITE_MALLOC_SOFT_LIMIT ){    new_size = SQLITE_MALLOC_SOFT_LIMIT/sizeof(struct _ht);  }  if( new_size==pH->htsize ) return 0;#endif  /* The inability to allocates space for a larger hash table is  ** a performance hit but it is not a fatal error.  So mark the  ** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of   ** sqlite3MallocZero() to make the allocation, as sqlite3MallocZero()  ** only zeroes the requested number of bytes whereas this module will  ** use the actual amount of space allocated for the hash table (which  ** may be larger than the requested amount).  */  sqlite3BeginBenignMalloc();  new_ht = (struct _ht *)sqlite3Malloc( new_size*sizeof(struct _ht) );  sqlite3EndBenignMalloc();  if( new_ht==0 ) return 0;  sqlite3_free(pH->ht);  pH->ht = new_ht;  pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);  memset(new_ht, 0, new_size*sizeof(struct _ht));  for(elem=pH->first, pH->first=0; elem; elem = next_elem){    unsigned int h = strHash(elem->pKey, elem->nKey) % new_size;    next_elem = elem->next;    insertElement(pH, &new_ht[h], elem);  }  return 1;}
开发者ID:0x7678,项目名称:owasp-igoat,代码行数:41,


示例20: sqlite3Malloc

/*** Allocate memory, either lookaside (if possible) or heap.  ** If the allocation fails, set the mallocFailed flag in** the connection pointer.**** If db!=0 and db->mallocFailed is true (indicating a prior malloc** failure on the same database connection) then always return 0.** Hence for a particular database connection, once malloc starts** failing, it fails consistently until mallocFailed is reset.** This is an important assumption.  There are many places in the** code that do things like this:****         int *a = (int*)sqlite3DbMallocRaw(db, 100);**         int *b = (int*)sqlite3DbMallocRaw(db, 200);**         if( b ) a[10] = 9;**** In other words, if a subsequent malloc (ex: "b") worked, it is assumed** that all prior mallocs (ex: "a") worked too.**** The sqlite3MallocRawNN() variant guarantees that the "db" parameter is** not a NULL pointer.*/void *sqlite3DbMallocRaw(sqlite3 *db, u64 n){  void *p;  if( db ) return sqlite3DbMallocRawNN(db, n);  p = sqlite3Malloc(n);  sqlite3MemdebugSetType(p, MEMTYPE_HEAP);  return p;}
开发者ID:ftes,项目名称:sqlite-simple-enclave,代码行数:29,


示例21: assert

/* Insert an element into the hash table pH.  The key is pKey** and the data is "data".**** If no element exists with a matching key, then a new** element is created and NULL is returned.**** If another element already exists with the same key, then the** new data replaces the old data and the old data is returned.** The key is not copied in this instance.  If a malloc fails, then** the new data is returned and the hash table is unchanged.**** If the "data" parameter to this function is NULL, then the** element corresponding to "key" is removed from the hash table.*/void *sqlite3HashInsert(Hash *pH, const char *pKey, void *data) {    unsigned int h;       /* the hash of the key modulo hash table size */    HashElem *elem;       /* Used to loop thru the element list */    HashElem *new_elem;   /* New element added to the pH */    assert( pH!=0 );    assert( pKey!=0 );    elem = findElementWithHash(pH,pKey,&h);    if( elem ) {        void *old_data = elem->data;        if( data==0 ) {            removeElementGivenHash(pH,elem,h);        } else {            elem->data = data;            elem->pKey = pKey;        }        return old_data;    }    if( data==0 ) return 0;    new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );    if( new_elem==0 ) return data;    new_elem->pKey = pKey;    new_elem->data = data;    pH->count++;    if( pH->count>=10 && pH->count > 2*pH->htsize ) {        if( rehash(pH, pH->count*2) ) {            assert( pH->htsize>0 );            h = strHash(pKey) % pH->htsize;        }    }    insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);    return 0;}
开发者ID:luobende,项目名称:gadgets,代码行数:47,


示例22: assert

/* Finish the work of sqlite3DbMallocRawNN for the unusual and** slower case when the allocation cannot be fulfilled using lookaside.*/static SQLITE_NOINLINE void *dbMallocRawFinish(sqlite3 *db, u64 n){  void *p;  assert( db!=0 );  p = sqlite3Malloc(n);  if( !p ) sqlite3OomFault(db);  sqlite3MemdebugSetType(p,          (db->lookaside.bDisable==0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);  return p;}
开发者ID:ftes,项目名称:sqlite-simple-enclave,代码行数:12,


示例23: sqlite3Malloc

static SQLITE_NOINLINE void *dbMallocRawFinish(sqlite3 *db, u64 n){  void *p = sqlite3Malloc(n);  if( !p && db ){    db->mallocFailed = 1;  }  sqlite3MemdebugSetType(p,          (db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);  return p;}
开发者ID:whr4935,项目名称:sqlite,代码行数:9,


示例24: sqlite3CodecAttach

int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey) {    struct Db *pDb = &db->aDb[nDb];    //RAWLOG_INFO("sqlite3CodecAttach");    if ( nKey && pKey && pDb->pBt )     {        Pager *pPager = sqlite3BtreePager(pDb->pBt);        sqlite3_file *fd;        CRhoSqliteCodecCtx* pRhoCtx = sqlite3Malloc(sizeof(CRhoSqliteCodecCtx));        memset(pRhoCtx, 0, sizeof(CRhoSqliteCodecCtx));        pRhoCtx->m_szPartition = sqlite3Malloc(nKey);        memcpy(pRhoCtx->m_szPartition, pKey, nKey);        pRhoCtx->m_nPartLen = nKey;        pRhoCtx->m_pPageBuffer = sqlite3Malloc(SQLITE_DEFAULT_PAGE_SIZE);        sqlite3PagerSetCodec( pPager, sqlite3Codec, NULL, sqlite3FreeCodecArg, (void *)pRhoCtx );        fd = (isOpen(pPager->fd)) ? pPager->fd : NULL;        sqlite3_mutex_enter(db->mutex);        /* Always overwrite page size and set to the default because the first page of the database        in encrypted and thus sqlite can't effectively determine the pagesize. this causes an issue in         cases where bytes 16 & 17 of the page header are a power of 2 as reported by John Lehman        Note: before forcing the page size we need to force pageSizeFixed to 0, else          sqliteBtreeSetPageSize will block the change         */        pDb->pBt->pBt->pageSizeFixed = 0;         sqlite3BtreeSetPageSize( pDb->pBt, SQLITE_DEFAULT_PAGE_SIZE, EVP_MAX_IV_LENGTH, 0 );        /* if fd is null, then this is an in-memory database and        we dont' want to overwrite the AutoVacuum settings        if not null, then set to the default */        if ( fd != NULL )             sqlite3BtreeSetAutoVacuum(pDb->pBt, SQLITE_DEFAULT_AUTOVACUUM);        sqlite3_mutex_leave(db->mutex);    }    return SQLITE_OK;}
开发者ID:4nkh,项目名称:rhodes,代码行数:44,


示例25: cipher_ctx_set_pass

/**  * Set the raw password / key data for a cipher context  *   * returns SQLITE_OK if assignment was successfull  * returns SQLITE_NOMEM if an error occured allocating memory  * returns SQLITE_ERROR if the key couldn't be set because the pass was null or size was zero  */static int cipher_ctx_set_pass(cipher_ctx *ctx, const void *zKey, int nKey) {  codec_free(ctx->pass, ctx->pass_sz);  ctx->pass_sz = nKey;  if(zKey && nKey) {    ctx->pass = sqlite3Malloc(nKey);    if(ctx->pass == NULL) return SQLITE_NOMEM;    memcpy(ctx->pass, zKey, nKey);    return SQLITE_OK;  }  return SQLITE_ERROR;}
开发者ID:TheDleo,项目名称:ocRosa,代码行数:18,


示例26: cipher_ctx_copy

/**  * Copy one cipher_ctx to another. For instance, assuming that read_ctx is a   * fully initialized context, you could copy it to write_ctx and all yet data  * and pass information across  *  * returns SQLITE_OK if initialization was successful  * returns SQLITE_NOMEM if an error occured allocating memory  */static int cipher_ctx_copy(cipher_ctx *target, cipher_ctx *source) {  void *key = target->key;   CODEC_TRACE(("cipher_ctx_copy: entered target=%d, source=%d/n", target, source));  codec_free(target->pass, target->pass_sz);   memcpy(target, source, sizeof(cipher_ctx));    target->key = key; //restore pointer to previously allocated key data  memcpy(target->key, source->key, EVP_MAX_KEY_LENGTH);  target->pass = sqlite3Malloc(source->pass_sz);  if(target->pass == NULL) return SQLITE_NOMEM;  memcpy(target->pass, source->pass, source->pass_sz);  return SQLITE_OK;}
开发者ID:TheDleo,项目名称:ocRosa,代码行数:21,


示例27: sqlite3_result_error_toobig

/*** Allocate nByte bytes of space using sqlite3_malloc(). If the** allocation fails, call sqlite3_result_error_nomem() to notify** the database handle that malloc() has failed.*/static void *contextMalloc(sqlite3_context *context, i64 nByte){  char *z;  if( nByte>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){    sqlite3_result_error_toobig(context);    z = 0;  }else{    z = sqlite3Malloc(nByte);    if( !z && nByte>0 ){      sqlite3_result_error_nomem(context);    }  }  return z;}
开发者ID:KnowNo,项目名称:test-code-backup,代码行数:18,



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


C++ sqlite3MallocFailed函数代码示例
C++ sqlite3MPrintf函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。