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


C++ Memcpy函数代码示例

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


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

示例1: quadform

double quadform(double *x, double *A, int N, int incx, int LDA)
{
  
  //quadform2 seems to be faster
  return( quadform2(x, A, N, incx, LDA) );
  
  int Nsqr = N*N,info,i=0,j=0;
  double *B = Calloc(Nsqr,double);
  //double one=1;
  //double zero=0;
  double sumSq=0;
  double y[N];
  int iOne=1;

  for(i=0;i<N;i++){
    y[i] = x[i*incx];
  }
  for(i=0;i<N;i++){
	Memcpy(&B[i*N],&A[i*LDA],N);
  }

  F77_NAME(dpotrf)("U", &N, B, &N, &info);
  F77_NAME(dtrmv)("U","N","N", &N, B, &N, y, &iOne);
  
  for(i=0;i<N;i++){
    sumSq += y[i]*y[i];
  }
  
  Free(B);
  
  return(sumSq);
}
开发者ID:rforge,项目名称:bayesfactorpcl,代码行数:32,代码来源:matrix.c

示例2: d_assert

VertexBufferPtr D3D9VideoBufferManager::CreateVertexBuffer(
	int size, int stride, USAGE usage, bool cpuAccess, const void * initData)
{
    d_assert (size > 0);

    HRESULT hr;
    DWORD D3DUsage = D3D9Mapping::GetD3DUsage(usage);
    D3DPOOL D3DPool = D3D9Mapping::GetD3DPool(usage);
    IDirect3DVertexBuffer9 * pD3DVB;

    hr = mD3D9Device->CreateVertexBuffer(size, D3DUsage, 0, D3DPool, &pD3DVB, NULL);

    if (FAILED(hr))
    {
        EXCEPTION("D3D Error: CreateVertexBuffer failed, desc: " + D3D9Mapping::GetD3DErrorDescription(hr));
    }

    D3D9VertexBuffer * pVB = new D3D9VertexBuffer(mD3D9Device);

    pVB->mD3D9VertexBuffer = pD3DVB;
    pVB->mSize = size;
	pVB->mStride = stride;
    pVB->mUsage = usage;

    mVertexBuffers.PushBack(pVB);

	if (initData != NULL)
	{
		void * data = pVB->Lock(0, 0, LOCK_DISCARD);
		Memcpy(data, initData, size);
		pVB->Unlock();
	}
	
    return VertexBufferPtr(pVB);
}
开发者ID:ak4hige,项目名称:myway3d,代码行数:35,代码来源:MWD3D9VideoBufferManager.cpp

示例3: check_gv

static
double* check_gv(SEXP gr, SEXP hs, SEXP rho, int n, double *gv, double *hv)
{
    SEXP gval = PROTECT(coerceVector(eval(gr, rho), REALSXP));
    if (LENGTH(gval) != n)
	error(_("gradient function must return a numeric vector of length %d"), n);
    Memcpy(gv, REAL(gval), n);
    for (int i = 0; i < n; i++)
	if(ISNAN(gv[i])) error("NA/NaN gradient evaluation");
    if (hv) {
	SEXP hval = PROTECT(eval(hs, rho));
	SEXP dim = getAttrib(hval, R_DimSymbol);
	int i, j, pos;
	double *rhval = REAL(hval);

	if (!isReal(hval) || LENGTH(dim) != 2 ||
	    INTEGER(dim)[0] != n || INTEGER(dim)[1] != n)
	    error(_("Hessian function must return a square numeric matrix of order %d"),
		  n);
	for (i = 0, pos = 0; i < n; i++) /* copy lower triangle row-wise */
	    for (j = 0; j <= i; j++) {
		hv[pos] = rhval[i + j * n];
		if(ISNAN(hv[pos])) error("NA/NaN Hessian evaluation");
		pos++;
	    }
	UNPROTECT(1);
    }
    UNPROTECT(1);
    return gv;
}
开发者ID:SensePlatform,项目名称:R,代码行数:30,代码来源:port.c

示例4: CopyVertex

void CopyVertex(PolygonGroup *srcGroup, uint32 srcPos, PolygonGroup *dstGroup, uint32 dstPos)
{
    int32 srcFormat = srcGroup->GetFormat();
    int32 dstFormat = dstGroup->GetFormat();
    int32 copyFormat = srcFormat&dstFormat;    //most common format;   

    uint8 *srcData = srcGroup->meshData+srcPos*GetVertexSize(srcFormat);
    uint8 *dstData = dstGroup->meshData+dstPos*GetVertexSize(dstFormat);
        
    for (uint32 mask = EVF_LOWER_BIT; mask <= EVF_HIGHER_BIT; mask = mask << 1)
    {
        int32 vertexAttribSize = GetVertexSize(mask);
        if (mask&copyFormat)
            Memcpy(dstData, srcData, vertexAttribSize);

        if (mask&srcFormat)
            srcData+=vertexAttribSize;
        
        if (mask&dstFormat)
            dstData+=vertexAttribSize;

         copyFormat&=~mask;
    }    
    
    /*unsupported stream*/
    DVASSERT((copyFormat == 0)&&"Unsupported attribute stream in copy");
    
}
开发者ID:galek,项目名称:dava.framework,代码行数:28,代码来源:MeshUtils.cpp

示例5: ASSERT_VALID

UINT CMemFile::Read(void* lpBuf, UINT nCount)
{
	ASSERT_VALID(this);

	if (nCount == 0)
		return 0;

	ASSERT(lpBuf != NULL);
	ASSERT(AfxIsValidAddress(lpBuf, nCount));

	if (m_nPosition > m_nFileSize)
		return 0;

	UINT nRead;
	if (m_nPosition + nCount > m_nFileSize)
		nRead = (UINT)(m_nFileSize - m_nPosition);
	else
		nRead = nCount;

	Memcpy((BYTE*)lpBuf, (BYTE*)m_lpBuffer + m_nPosition, nRead);
	m_nPosition += nRead;

	ASSERT_VALID(this);

	return nRead;
}
开发者ID:anyue100,项目名称:winscp,代码行数:26,代码来源:filemem.cpp

示例6: Memcpy

 void CD3DDevice::UpdateBuffer( IGfxBuffer* pBuffer, void* pData, uint nSize )
 {
     D3D11_MAPPED_SUBRESOURCE pMappedBuffer;
     m_pContext->Map( ((CD3DBuffer*)pBuffer)->m_pBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &pMappedBuffer );
     Memcpy( pMappedBuffer.pData, pData, nSize );
     m_pContext->Unmap( ((CD3DBuffer*)pBuffer)->m_pBuffer, 0 );
 }
开发者ID:10n1,项目名称:RiotPrototype,代码行数:7,代码来源:D3DGraphics.cpp

示例7: cache_writesector

int32
cache_writesector(
    IN  tcache_t * pcache,
    IN  int32 addr,
    IN  ubyte * ptr)
{
	int16 secindex;
	int32 ret;

	ret = CACHE_OK;

	if (!pcache->use_cache) {
		return HAI_readsector(pcache->hdev, addr, ptr);
	}

	if (!_find_in_list(pcache, addr, &secindex)) {
		if ((secindex = _do_cache_miss(pcache, secindex, addr)) < 0) {
			ret = secindex;
		}
	}
	else {
		_do_cache_hint(pcache, secindex);
	}

	if (ret >= 0) {
		Memcpy(pcache->secbufs[secindex].secbuf, ptr, pcache->sector_size);
		pcache->secbufs[secindex].is_dirty = 1;
	}

	return ret;
}
开发者ID:ralt,项目名称:tffs-lib,代码行数:31,代码来源:cache.c

示例8: matrixDet

// Compute determinant of an N by N positive definite matrix A
double matrixDet(double *A, int N, int LDA, int doLog, int *info)
{
//SUBROUTINE DPOTRF( UPLO, N, A, LDA, INFO )
	int i=0;
	double B[N*N], logDet=0;
	
	//Memcpy(B,A,N*N);
	for(i=0;i<N;i++){
		Memcpy(&B[i*N],&A[i*LDA],N);
	}
	
	F77_CALL(dpotrf)("U", &N, B, &N, info);
	if(*info){
		Rprintf("Cholesky decomposition in matrixDet() returned nonzero info %d.\n",info);
	}
	
	for(i=0;i<N;i++)
	{
		logDet += 2 * log(B[i*N+i]);
	}
	
	if(doLog){
		return(logDet);
	}else{
		return(exp(logDet));
	}
}
开发者ID:rforge,项目名称:bayesfactorpcl,代码行数:28,代码来源:matrix.c

示例9: dgCMatrix_QR

// Modified version of Tim Davis's cs_qr_mex.c file for MATLAB (in CSparse)
//  Usage: [V,beta,p,R,q] = cs_qr(A) ;
SEXP dgCMatrix_QR(SEXP Ap, SEXP order)
{
    CSP A = AS_CSP__(Ap), D;
    int io = INTEGER(order)[0];
    Rboolean verbose = (io < 0);
    int m = A->m, n = A->n, ord = asLogical(order) ? 3 : 0, *p;
    R_CheckStack();

    if (m < n) error(_("A must have #{rows} >= #{columns}")) ;
    SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("sparseQR")));
    int *dims = INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2));
    dims[0] = m; dims[1] = n;
    css *S = cs_sqr(ord, A, 1);	/* symbolic QR ordering & analysis*/
    if (!S) error(_("cs_sqr failed"));
    if(verbose && S->m2 > m) // in ./cs.h , m2 := # of rows for QR, after adding fictitious rows
	Rprintf("Symbolic QR(): Matrix structurally rank deficient (m2-m = %d)\n",
		S->m2 - m);
    csn *N = cs_qr(A, S);		/* numeric QR factorization */
    if (!N) error(_("cs_qr failed")) ;
    cs_dropzeros(N->L);		/* drop zeros from V and sort */
    D = cs_transpose(N->L, 1); cs_spfree(N->L);
    N->L = cs_transpose(D, 1); cs_spfree(D);
    cs_dropzeros(N->U);		/* drop zeros from R and sort */
    D = cs_transpose(N->U, 1); cs_spfree(N->U) ;
    N->U = cs_transpose(D, 1); cs_spfree(D);
    m = N->L->m;		/* m may be larger now */
    // MM: m := S->m2  also counting the ficticious rows (Tim Davis, p.72, 74f)
    p = cs_pinv(S->pinv, m);	/* p = pinv' */
    SET_SLOT(ans, install("V"),
	     Matrix_cs_to_SEXP(N->L, "dgCMatrix", 0));
    Memcpy(REAL(ALLOC_SLOT(ans, install("beta"),
			   REALSXP, n)), N->B, n);
    Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_pSym,
			      INTSXP, m)), p, m);
    SET_SLOT(ans, install("R"),
	     Matrix_cs_to_SEXP(N->U, "dgCMatrix", 0));
    if (ord)
	Memcpy(INTEGER(ALLOC_SLOT(ans, install("q"),
				  INTSXP, n)), S->q, n);
    else
	ALLOC_SLOT(ans, install("q"), INTSXP, 0);
    cs_nfree(N);
    cs_sfree(S);
    cs_free(p);
    UNPROTECT(1);
    return ans;
}
开发者ID:csilles,项目名称:cxxr,代码行数:49,代码来源:dgCMatrix.c

示例10: R_alloc

/**
   Copy cholmod_triplet to an R_alloc()ed version of it
 */
static void chTr2Ralloc(CHM_TR dest, CHM_TR src)
{
    int nnz;

    /* copy all the (non-pointer) characteristics of src to dest */
    memcpy(dest, src, sizeof(cholmod_triplet));

    /* R_alloc the vector storage for dest and copy the contents from src */
    nnz = src->nnz;
    dest->i = (void*) Memcpy((int*)R_alloc(nnz, sizeof(int)),
			     (int*)(src->i), nnz);
    dest->j = (void*) Memcpy((int*)R_alloc(nnz, sizeof(int)),
			     (int*)(src->j), nnz);
    if(src->xtype)
	dest->x = (void*) Memcpy((double*)R_alloc(nnz, sizeof(double)),
				 (double*)(src->x), nnz);
}
开发者ID:cran,项目名称:Matrix,代码行数:20,代码来源:chm_common.c

示例11: dtCMatrix_sparse_solve

SEXP dtCMatrix_sparse_solve(SEXP a, SEXP b)
{
    SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix")));
    CSP A = AS_CSP(a), B = AS_CSP(b);
    int *xp = INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, (B->n) + 1)),
	xnz = 10 * B->p[B->n];	/* initial estimate of nnz in x */
    int *ti = Calloc(xnz, int), k, lo = uplo_P(a)[0] == 'L', pos = 0;
    double *tx = Calloc(xnz, double);
    double  *wrk = Alloca(A->n, double);
    int *xi = Alloca(2*A->n, int);	/* for cs_reach */
    R_CheckStack();

    if (A->m != A->n || B->n < 1 || A->n < 1 || A->n != B->m)
	error(_("Dimensions of system to be solved are inconsistent"));
    slot_dup(ans, b, Matrix_DimSym);
    SET_DimNames(ans, b);
    xp[0] = 0;
    for (k = 0; k < B->n; k++) {
	int top = cs_spsolve (A, B, k, xi, wrk, (int *)NULL, lo);
	int nz = A->n - top, p;

	xp[k + 1] = nz + xp[k];
	if (xp[k + 1] > xnz) {
	    while (xp[k + 1] > xnz) xnz *= 2;
	    ti = Realloc(ti, xnz, int);
	    tx = Realloc(tx, xnz, double);
	}
	if (lo)			/* increasing row order */
	    for(p = top; p < A->n; p++, pos++) {
		ti[pos] = xi[p];
		tx[pos] = wrk[xi[p]];
	    }
	else			/* decreasing order, reverse copy */
	    for(p = A->n - 1; p >= top; p--, pos++) {
		ti[pos] = xi[p];
		tx[pos] = wrk[xi[p]];
	    }
    }
    xnz = xp[B->n];
    Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP,  xnz)), ti, xnz);
    Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, xnz)), tx, xnz);

    Free(ti); Free(tx);
    UNPROTECT(1);
    return ans;
}
开发者ID:rforge,项目名称:matrix,代码行数:46,代码来源:dtCMatrix.c

示例12: handlemessage

/*parse the response message and manipulate the send message*/
static int handlemessage(struct dhcp_msg*rmsg,struct dhcp_msg*smsg)
{
	int i,j,p;
	/*find DNS info*/
	if(getdns){
		p=messagefindoption(rmsg,OPT_DNS_SERVER);
		if(p>=0){
			for(i=0;i<rmsg->msg_opt[p].opt_dns_server.num_dns;i++)
				addaddr(dnsservers,rmsg->msg_opt[p].opt_dns_server.addr[i]);
		}
		p=messagefindoption(rmsg,OPT_DNS_NAME);
		if(p>=0){
			for(i=0;i<rmsg->msg_opt[p].opt_dns_name.num_dns;i++)
				adddomain(rmsg->msg_opt[p].opt_dns_name.namelist[i]);
		}
	}
	/*find PREFIX info*/
	if(getprefix){
		p=messagefindoption(rmsg,OPT_IAPD);
		if(p>=0)
		for(i=0;i<rmsg->msg_opt[p].opt_numopts;i++)
			if(rmsg->msg_opt[p].subopt[i].opt_type==OPT_IAPREFIX){
				j=addaddr(prefixes,rmsg->msg_opt[p].subopt[i].opt_iaprefix.prefix);
				if(j>=0)
					prefixlens[j]=rmsg->msg_opt[p].subopt[i].opt_iaprefix.prefixlen;
			}
	}
	/*find IANA info*/
	if(getaddress){
		p=messagefindoption(rmsg,OPT_IANA);
		if(p>=0)
		for(i=0;i<rmsg->msg_opt[p].opt_numopts;i++)
			if(rmsg->msg_opt[p].subopt[i].opt_type==OPT_IAADDR)
				addaddr(addresses,rmsg->msg_opt[p].subopt[i].opt_iaaddress.addr);
	}
	/*copy server address*/
	Memcpy(&dhcpserver,&rmsg->msg_peer.sin6_addr,16);
	/*check for rapid commit or type=REPLY; if so: tell caller it can stop now*/
	if(rmsg->msg_type==MSG_REPLY)return 0;
	if(messagefindoption(rmsg,OPT_RAPIDCOMMIT)>=0)return 0;
	/*otherwise we need to continue*/
	/*correct message type & id*/
	clearrecvfilter();
	if(getprefix||getaddress){
		addrecvfilter(MSG_REPLY);
		smsg->msg_type=MSG_REQUEST;
	}else{
		addrecvfilter(MSG_REPLY);
		smsg->msg_type=MSG_IREQUEST;
	}
	smsg->msg_id++; /*elapsed time continues to count*/
	/*rapid commit is no longer applicable*/
	messageremoveoption(smsg,OPT_RAPIDCOMMIT);
	/*append server ID*/
	p=messagefindoption(rmsg,OPT_SERVERID);
	if(p>=0)messageappendopt(smsg,&rmsg->msg_opt[p]);
	return 1;
}
开发者ID:kanghuanyao,项目名称:yao_env,代码行数:59,代码来源:client.c

示例13: KeyBlockCreate_external

/* TODO(gauravsh): This could easily be integrated into KeyBlockCreate()
 * since the code is almost a mirror - I have kept it as such to avoid changing
 * the existing interface. */
VbKeyBlockHeader* KeyBlockCreate_external(const VbPublicKey* data_key,
                                          const char* signing_key_pem_file,
                                          uint64_t algorithm,
                                          uint64_t flags,
                                          const char* external_signer) {
  VbKeyBlockHeader* h;
  uint64_t signed_size = sizeof(VbKeyBlockHeader) + data_key->key_size;
  uint64_t block_size = (signed_size + SHA512_DIGEST_SIZE +
                         siglen_map[algorithm]);
  uint8_t* data_key_dest;
  uint8_t* block_sig_dest;
  uint8_t* block_chk_dest;
  VbSignature *sigtmp;

  /* Allocate key block */
  h = (VbKeyBlockHeader*)malloc(block_size);
  if (!h)
    return NULL;
  if (!signing_key_pem_file || !data_key || !external_signer)
    return NULL;

  data_key_dest = (uint8_t*)(h + 1);
  block_chk_dest = data_key_dest + data_key->key_size;
  block_sig_dest = block_chk_dest + SHA512_DIGEST_SIZE;

  Memcpy(h->magic, KEY_BLOCK_MAGIC, KEY_BLOCK_MAGIC_SIZE);
  h->header_version_major = KEY_BLOCK_HEADER_VERSION_MAJOR;
  h->header_version_minor = KEY_BLOCK_HEADER_VERSION_MINOR;
  h->key_block_size = block_size;
  h->key_block_flags = flags;

  /* Copy data key */
  PublicKeyInit(&h->data_key, data_key_dest, data_key->key_size);
  PublicKeyCopy(&h->data_key, data_key);

  /* Set up signature structs so we can calculate the signatures */
  SignatureInit(&h->key_block_checksum, block_chk_dest,
                SHA512_DIGEST_SIZE, signed_size);
  SignatureInit(&h->key_block_signature, block_sig_dest,
                siglen_map[algorithm], signed_size);

  /* Calculate checksum */
  sigtmp = CalculateChecksum((uint8_t*)h, signed_size);
  SignatureCopy(&h->key_block_checksum, sigtmp);
  free(sigtmp);

  /* Calculate signature */
  sigtmp = CalculateSignature_external((uint8_t*)h, signed_size,
                                       signing_key_pem_file, algorithm,
                                       external_signer);
  SignatureCopy(&h->key_block_signature, sigtmp);
  free(sigtmp);

  /* Return the header */
  return h;
}
开发者ID:Chainfire,项目名称:vboot_android,代码行数:59,代码来源:host_keyblock.c

示例14: GrowFile

void CMemFile::Write( const void *lpBuf, UINT nCount )
/****************************************************/
{
    if( m_nPosition + nCount >= m_nFileSize ) {
        m_nFileSize = m_nPosition + nCount;
        GrowFile( m_nFileSize );
    }
    Memcpy( m_lpBuffer + m_nPosition, (const BYTE *)lpBuf, nCount );
    m_nPosition += nCount;
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:10,代码来源:memfile.cpp

示例15: Memcpy

void* HcpNI::Memcpy(void* pDest, const void* pSource, const hcp_Size_t Length, void* pContext) {
	void* result = NULL;

	if (pContext != NULL) {
		auto hni = static_cast<HcpNI*>(pContext);
		result = hni->Memcpy(pDest, pSource, Length);
	}

	return result;
}
开发者ID:adamarvid,项目名称:hcp,代码行数:10,代码来源:HcpNI.cpp


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