u32 mxRenderMesh::CopyFromMesh( const ::irr::scene::IMesh* mesh ) { if ( mesh->getMeshBufferCount() > 0 ) { if ( mesh->getMeshBufferCount() > 1 ) { Unimplemented2( "multiple mesh buffers" ); } ::irr::scene::IMeshBuffer * pBuf = mesh->getMeshBuffer( 0 ); Assert( pBuf ); Assert2( pBuf->getIndexType() == ::irr::video::E_INDEX_TYPE::EIT_16BIT, "only 16-bit indices are supported !" ); Assert2( pBuf->getVertexType() == ::irr::video::E_VERTEX_TYPE::EVT_STANDARD, "only standard vertex type is supported !" ); const TVertex * pVertices = ( TVertex* ) pBuf->getVertices(); const u32 vertexCount = pBuf->getVertexCount(); Vertices.SetNum( vertexCount ); MemCopy( Vertices.Ptr(), pVertices, vertexCount * sizeof( TVertex ) ); const TIndex * pIndices = pBuf->getIndices(); const u32 triangleCount = pBuf->getIndexCount() / 3; Triangles.SetNum( triangleCount ); MemCopy( Triangles.Ptr(), pIndices, pBuf->getIndexCount() * sizeof( TIndex ) ); // GCommon->DebugPrint( "* Loaded mesh: %u verts, %u tris\n", vertexCount, triangleCount ); return triangleCount; } return 0; }
void StartReceiveImages() { uint16_t rowReceived = 0; uint16_t bytesInRowReceived = 0; uint16_t const bytesInARow = 720; while (true) { RefreshButtonState(&leftButton, NULL); RefreshButtonState(&rightButton, NULL); RefreshLEDState(false, LED_MAX_BRIGHTNESS); if (NRF24L01_DataReady()) { NRF24L01_GetData(dataIn); if (!mem_cmp(startCommand, dataIn, 32)) { RefreshLEDState(true, LED_MAX_BRIGHTNESS); Delay_ms(50); _receivingImage = 1; rowReceived = 0; bytesInRowReceived = 0; LCDInitializeDataSend(); continue; } if (_receivingImage) { MemCopy(dataIn, rowData, 0, bytesInRowReceived, 32); bytesInRowReceived += 32; if (bytesInRowReceived >= bytesInARow) { LCDFillRow(rowData); bytesInRowReceived = bytesInRowReceived - bytesInARow; MemCopy(dataIn, rowData, bytesInRowReceived, 0, bytesInRowReceived); rowReceived++; if (rowReceived == 320) { RefreshLEDState(false, LED_MAX_BRIGHTNESS); _receivingImage = 0; rowReceived = 0; bytesInRowReceived = 0; LCDFinishDataSend(); } } } } } }
HTREEITEM CTreeCtrl::FindItem(LPCSTR pText,BOOL bBackwardDirection,BOOL bPartial,HTREEITEM hItem,HTREEITEM hEnd) const { TV_ITEMA ti; char szBuffer[1000]; ti.mask=TVIF_TEXT; ti.hItem=hItem; ti.pszText=szBuffer; ti.cchTextMax=1000; LPSTR pTextMod; if (bPartial) { int iStrLen=istrlen(pText); pTextMod=new char[iStrLen+3]; if (pText[0]!='*') { pTextMod[0]='*'; MemCopy(pTextMod+1,pText,iStrLen++); } else MemCopy(pTextMod,pText,iStrLen); if (pTextMod[iStrLen-1]!='*') pTextMod[iStrLen++]='*'; pTextMod[iStrLen]='\0'; MakeLower(pTextMod); } while ((ti.hItem=bBackwardDirection?GetPrevItem(ti.hItem):GetNextItem(ti.hItem))!=NULL) { // Get next item if (ti.hItem==hEnd) return NULL; // Check text if (!GetItem(&ti)) continue; if (bPartial) { MakeLower(szBuffer); if (ContainString(szBuffer,pTextMod)) { delete[] pTextMod; return ti.hItem; } } else if (_stricmp(szBuffer,pText)==0) return ti.hItem; } if (bPartial) delete[] pTextMod; return NULL; }
void main(void) { InitSysCtrl(); // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: epwm1_timer_isr(), epwm2_timer_isr() // epwm3_timer_isr and and InitFlash(); // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart // symbols are created by the linker. Refer to the F28335.cmd file. // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2833x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP2833x_DefaultIsr.c. // This function is found in DSP2833x_PieVect.c. InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.SEQ1INT = &PWM_AD_isr; PieVectTable.ECAN0INTA = &Skiip4_CAN_isr; EDIS; // This is needed to disable write to EALLOW protected registers InitFlash(); MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); MemCopy(&IQmathLoadStart, &IQmathLoadEnd, &IQmathRunStart); //ECan-A模块初始化 InitECan(); InitECan1(); InitGpio(); // Skipped for this example InitAdc(); // Initialize necessary ADC module, directly for SVPWM. InitEPwm(); IER |= M_INT1; // Enable SEQ1_INT which is connected to PIE1.1: IER |= M_INT9; // Enable eCAN0-A INT which is connected to PIE9.5: EINT; } // end of main()
inline void MemSwap( T* a, T* b, T* temp, size_t numEntries ) { // temp := a MemCopy( temp, a, numEntries ); // a := b MemCopy( a, b, numEntries ); // b := temp MemCopy( b, temp, numEntries ); }
const DistMatrix<T,STAR,STAR>& DistMatrix<T,STAR,STAR>::operator=( const DistMatrix<T,STAR,VR>& A ) { #ifndef RELEASE CallStackEntry entry("[* ,* ] = [* ,VR]"); this->AssertNotLocked(); this->AssertSameGrid( A.Grid() ); #endif const elem::Grid& g = this->Grid(); this->ResizeTo( A.Height(), A.Width() ); if( !this->Participating() ) return *this; const Int p = g.Size(); const Int height = this->Height(); const Int width = this->Width(); const Int localWidthOfA = A.LocalWidth(); const Int maxLocalWidth = MaxLength(width,p); const Int portionSize = mpi::Pad( height*maxLocalWidth ); T* buffer = this->auxMemory_.Require( (p+1)*portionSize ); T* sendBuf = &buffer[0]; T* recvBuf = &buffer[portionSize]; // Pack const Int ALDim = A.LDim(); const T* ABuf = A.LockedBuffer(); PARALLEL_FOR for( Int jLoc=0; jLoc<localWidthOfA; ++jLoc ) MemCopy( &sendBuf[jLoc*height], &ABuf[jLoc*ALDim], height ); // Communicate mpi::AllGather ( sendBuf, portionSize, recvBuf, portionSize, g.VRComm() ); // Unpack T* thisBuf = this->Buffer(); const Int thisLDim = this->LDim(); const Int rowAlignmentOfA = A.RowAlignment(); OUTER_PARALLEL_FOR for( Int k=0; k<p; ++k ) { const T* data = &recvBuf[k*portionSize]; const Int rowShift = Shift_( k, rowAlignmentOfA, p ); const Int localWidth = Length_( width, rowShift, p ); INNER_PARALLEL_FOR for( Int jLoc=0; jLoc<localWidth; ++jLoc ) MemCopy ( &thisBuf[(rowShift+jLoc*p)*thisLDim], &data[jLoc*height], height ); } this->auxMemory_.Release(); return *this; }
inline void MemSwap( BigFloat* a, BigFloat* b, BigFloat* temp, size_t numEntries ) { // NOTE: This is the same as above for now // temp := a MemCopy( temp, a, numEntries ); // a := b MemCopy( a, b, numEntries ); // b := temp MemCopy( b, temp, numEntries ); }
/*************************************************************************** * * Function to put the string into the buffer * ***************************************************************************/ SINT WriteNewLineObject(MEMPTR lpMem, MEMPTR Obj) { SINT Res1, Res2; Res1 = lstrlen(NewLine); MemCopy(lpMem, NewLine, Res1); lpMem += Res1; Res2 = lstrlen(Obj); MemCopy(lpMem, Obj, Res2); return( Res1 + Res2 ); }
/***************************************************************************** * * ByteStorePtr AsnLexReadOctets(aip, atp) * expects Octets type next * assumes none of it has already been read * does not advance to next token * atp points to the definition of this OCTET STRING * *****************************************************************************/ NLM_EXTERN ByteStorePtr AsnLexReadOctets (AsnIoPtr aip, AsnTypePtr atp) { Int2 token, len; ByteStorePtr ssp = NULL; Byte tbuf[256]; /* was 101 - changed to handle occasional hand-edited ASN.1? */ Int4 bytes, left, added; token = AsnLexWord(aip); /* read the start */ if (token != START_BITHEX) { AsnIoErrorMsg(aip, 45, AsnErrGetTypeName(atp->name), aip->linenumber); return NULL; } ssp = BSNew(0); if (ssp == NULL) return ssp; token = AsnLexWord(aip); /* read the octet(s) */ left = 0; while (token == IN_BITHEX) { len = (Int2)(aip->wordlen + left); MemCopy((tbuf + left), aip->word, (len - left)); tbuf[len] = '\0'; added = AsnTypeStringToHex(tbuf, len, tbuf, &left); if (added < 0) { AsnIoErrorMsg(aip, 46, AsnErrGetTypeName(atp->name), aip->linenumber); return NULL; } if (added) { bytes = BSWrite(ssp, tbuf, added); if (bytes != added) { ssp = BSFree(ssp); return ssp; } } if (left) /* left a char */ { MemCopy(tbuf, ((aip->word)+(aip->wordlen - left)),left); } token = AsnLexWord(aip); } if (token != OCTETS) { AsnIoErrorMsg(aip, 47, AsnErrGetTypeName(atp->name), aip->linenumber); return NULL; } return ssp; }
inline void BlendFill( NormalPixel color, GenericPixelPtr<DstPixelType> d_line, const unsigned char *a_line, int a_pitch, int w, int h, bool inverted, int alpha_0, int alpha_1 ) { size_t line_size = w * sizeof(DstPixelType); MemBlock d_cache( line_size ); while ( h-- ) { MemCopy( d_cache.GetPtr(), (DstPixelType*)d_line, line_size ); DstPixelType *d_ptr = (DstPixelType*)d_cache.GetPtr(); const unsigned char *a_ptr = a_line; if ( alpha_0>0 || alpha_1<256 ) { if (!inverted) for ( int i=w; i--; ++a_ptr, ++d_ptr ) { BlendPixel( *d_ptr, color, *a_ptr *(alpha_1-alpha_0)/256+alpha_0 ); } else for ( int i=w; i--; ++a_ptr, ++d_ptr ) { BlendPixel( *d_ptr, color, (255-*a_ptr) *(alpha_1-alpha_0)/256+alpha_0 ); } } else if (!inverted) for ( int i=w; i--; ++a_ptr, ++d_ptr ) { BlendPixel( *d_ptr, color, *a_ptr ); } else for ( int i=w; i--; ++a_ptr, ++d_ptr ) { BlendPixel( *d_ptr, color, 255-*a_ptr ); } MemCopy( (DstPixelType*)d_line, d_cache.GetPtr(), line_size ); d_line.Next(); a_line += a_pitch; } }
static void Func ( DistMatrix<T,STAR,MR>& A, T center, typename Base<T>::type radius ) { const Grid& grid = A.Grid(); const int m = A.Height(); const int localWidth = A.LocalWidth(); const int bufSize = m*localWidth; std::vector<T> buffer( bufSize ); // Create random matrix on process row 0, then broadcast if( grid.Row() == 0 ) { for( int j=0; j<localWidth; ++j ) for( int i=0; i<m; ++i ) buffer[i+j*m] = center+radius*SampleUnitBall<T>(); } mpi::Broadcast( &buffer[0], bufSize, 0, grid.ColComm() ); // Unpack T* localBuffer = A.LocalBuffer(); const int ldim = A.LocalLDim(); #ifdef HAVE_OPENMP #pragma omp parallel for #endif for( int jLocal=0; jLocal<localWidth; ++jLocal ) { const T* bufferCol = &buffer[jLocal*m]; T* col = &localBuffer[jLocal*ldim]; MemCopy( col, bufferCol, m ); } }
void PrintNextImage(volatile void *uselessParameter) { _receivingImage = 0; if (previousFileIsValid) { uint16_t stringLength = strlen(fno.fname) + 1; MemCopy(fno.fname, previousFileName, 0, 0, stringLength); } FRESULT res; res = pf_readdir(&dir, &fno); if (res == FR_NO_FILE) { char *rootDir = " "; pf_opendir(&dir, rootDir); res = pf_readdir(&dir, &fno); if (res == FR_NO_FILE) { return; } } if (!CheckBMPImage(fno.fname)) { previousFileIsValid = true; PrintImage(fno.fname); } }
LPWSTR allocstringW(UINT nID,TypeOfResourceHandle bType) { LPWSTR szBuffer; szBuffer=new WCHAR[STR_LOADSTRINGBUFLEN]; if (szBuffer==NULL) { SetHFCError(HFC_CANNOTALLOCATE); return NULL; } UINT nDataLen=::LoadString(nID,szBuffer,STR_LOADSTRINGBUFLEN,bType); if (nDataLen>=STR_LOADSTRINGBUFLEN-2) { for (DWORD i=2;nDataLen>=i*STR_LOADSTRINGBUFLEN-2;i++) { delete[] szBuffer; szBuffer=new WCHAR[i*STR_LOADSTRINGBUFLEN]; nDataLen=::LoadString(nID,szBuffer,i*STR_LOADSTRINGBUFLEN,bType); } } WCHAR* pText=new WCHAR[nDataLen+1]; MemCopy(pText,szBuffer,(nDataLen+1)*2); delete[] szBuffer; return pText; }
/* Collapse multiple IDAT chunks into single one. */ static void MergeIDATs(PngT *png) { if (png->idat.next) { uint32_t length, i; uint8_t *data; IdatT *idat; for (idat = &png->idat, length = 0; idat; idat = idat->next) length += idat->length; LOG("Merged chunk length: %d.", length); data = MemNew(length); for (idat = &png->idat, i = 0; idat;) { IdatT *next = idat->next; MemCopy(data + i, idat->data, idat->length); i += idat->length; MemUnref(idat->data); if (idat != &png->idat) MemUnref(idat); idat = next; } png->idat.data = data; png->idat.length = length; png->idat.next = NULL; } }
extern void GapSetReconnectionAddress(uint8 *p_val) { if(p_val == NULL) { MAKE_RECONNECTION_ADDRESS_INVALID(); } else { /* Every byte of re-connection address is stored as a word in the * firmware buffer. So, first create a variable of type BD_ADDR_T * and copy the data from the firmware buffer to this variable. */ BD_ADDR_T temp_reconnect_address; temp_reconnect_address.lap = p_val[0] | p_val[1] << 8 | (uint24)p_val[2] << 16; temp_reconnect_address.uap = p_val[3]; temp_reconnect_address.nap = p_val[4] | p_val[5] << 8; MemCopy(&g_gap_data.reconnect_address, &temp_reconnect_address, sizeof(BD_ADDR_T)); } /* Write re-connection address to NVM */ Nvm_Write((uint16*)&g_gap_data.reconnect_address, sizeof(BD_ADDR_T), g_gap_data.nvm_offset + GAP_NVM_DEVICE_RECONNECTION_ADDRESS_OFFSET); /* The updated reconnection address needs to be in whitelist as the remote * host may connect using this address during re-connection. */ AppUpdateWhiteList(); }
/***************************************************************************** * * PrintStackSortNextItem(dest, src, index, indent, next) * Copies src[index] item to next available slot in dest * Also copies sorted list of any subcomponents * returns index to next item (based on sort_key) at this indent level * returns -1 when no more items * *****************************************************************************/ static void PrintStackSortNextItem (PrintStackPtr dest, PrintStackPtr src, Int2 index, Int2 indent) { Int2 tmp, max_key, min_key; PrintStackItemPtr from, to; if ((dest == NULL) || (src == NULL)) return; to = PrintStackItemNew(dest); /* copy the one */ from = src->data + index; MemCopy(to, from, sizeof(PrintStackItem)); min_key = from->pfip->sort_key; max_key = PrintFormatListGetMaxKey(src->pflp, min_key); /* any components to copy? */ tmp = PrintStackGetLowest(src, (Int2)(index + 1), (Int2)(indent + 1), index, max_key, min_key); while (tmp >= 0) /* copy/sort any components */ { PrintStackSortNextItem(dest, src, tmp, (Int2)(indent + 1)); tmp = PrintStackGetLowest(src, (Int2)(index + 1), (Int2)(indent+1), tmp, max_key, min_key); } return; }
// // Read functions // int ext2::ReadInode(ulong inode, Inode *theInode) { if(inode < 2) { Panic::PrintMessage("Tried to get inode zero\n"); return(-1); } ulong groupNumber = inode / theSuperBlock.inodesPerGroup; // DivUp(inode, theSuperBlock.inodesPerGroup); ulong blocksNeeded = DivUp(theSuperBlock.inodesPerGroup * sizeof(Inode), blockSize); // cal the blocks needed for all inodes uchar *buff = new uchar[blocksNeeded * blockSize]; Inode *tmpInode = reinterpret_cast<Inode*>(buff); /* printf("INODE: %d\n", inode); printf("INODES PER GROUP: %d\n", theSuperBlock.inodesPerGroup); printf("GROUP NUMBER: %d\n", groupNumber); printf("INODE TABLE ADDR: %d\n", theGroupDescriptors[groupNumber].inodeTableAddress); printf("BLOCKS REQUESTED: %d\n", blocksNeeded); printf("INODE SIZE: %d\n", sizeof(Inode)); */ // read the inode table for that group int ret = ReadBlocks(theGroupDescriptors[groupNumber].inodeTableAddress, blocksNeeded, buff); if(ret >= 0) // decrease inode because array index at zero and inodes at one MemCopy(theInode, &tmpInode[(inode-1) % theSuperBlock.inodesPerGroup], sizeof(Inode)); delete [] buff; return(ret); }
Bool System::EnumResolvedNetAddresses( NetAddress * outAddress, SocketProtocol * outProtocol ) { if ( m_pCurAddrInfo == NULL ) return false; *outProtocol = HSocket::_BuildSocketProtocol( m_pCurAddrInfo->ai_socktype, m_pCurAddrInfo->ai_family, m_pCurAddrInfo->ai_protocol ); if ( (*outProtocol) & 0x80000000 ) { NetAddressIPv6 * outIPv6 = (NetAddressIPv6*)outAddress; outIPv6->iType = NETADDRESS_IPv6; SOCKADDR_IN6 * pAddr = (SOCKADDR_IN6*)( m_pCurAddrInfo->ai_addr ); outIPv6->dwFlowInfo = pAddr->sin6_flowinfo; outIPv6->dwScopeID = pAddr->sin6_scope_id; MemCopy( outIPv6->Addr.Bytes, pAddr->sin6_addr.s6_addr, 16 ); outIPv6->wPort = pAddr->sin6_port; } else { NetAddressIPv4 * outIPv4 = (NetAddressIPv4*)outAddress; outIPv4->iType = NETADDRESS_IPv4; SOCKADDR_IN * pAddr = (SOCKADDR_IN*)( m_pCurAddrInfo->ai_addr ); outIPv4->Addr.Value = pAddr->sin_addr.s_addr; outIPv4->wPort = pAddr->sin_port; } m_pCurAddrInfo = m_pCurAddrInfo->ai_next; return ( m_pCurAddrInfo != NULL ); }
int ext2::Read(FileDescriptorBase *fileDescriptor, void *buff, uint numBytes) { if(numBytes == 0) return(0); FileDescriptor *tmpDescriptor = reinterpret_cast<FileDescriptor*>(fileDescriptor); uint bytesToRead = MIN(tmpDescriptor->fileInode.size - tmpDescriptor->filePosition, numBytes); uint bytesRead = 0; int amt; // this could be faster by reading directly into buff and saving a mem copy... but easier to code :-) while(bytesToRead > bytesRead) { amt = MIN(blockSize - tmpDescriptor->blockPosition, bytesToRead - bytesRead); // copy over the data MemCopy(reinterpret_cast<uchar*>(buff) + bytesRead, tmpDescriptor->blockData + tmpDescriptor->blockPosition, amt); tmpDescriptor->blockPosition += amt; tmpDescriptor->filePosition += amt; // check if we're done with this block and need to read in the next one if(tmpDescriptor->blockPosition == blockSize && tmpDescriptor->filePosition < tmpDescriptor->fileInode.size) { ReadDataBlock(++tmpDescriptor->blockNumber, tmpDescriptor->fileInode.blockPointers, tmpDescriptor->blockData); tmpDescriptor->blockPosition = 0; } bytesRead += amt; } return(bytesRead); }
WatchID FileWatcherWin32::addWatch(const mxChar* directory) { WatchID watchid = ++mLastWatchID; WatchStruct* watch = CreateWatch( directory, FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_FILE_NAME); if( !watch ) { mxErrf( "CreateWatch() failed, directory: %s", mxTO_ANSI(directory) ); return 0; } watch->mWatchid = watchid; watch->mWatcher = this; const size_t strLen = (mxStrLen(directory)) *sizeof(directory[0]); Assert( strLen < sizeof(watch->mDirName)); watch->mDirName.SetNum(strLen + 1); MemCopy(watch->mDirName.ToChars(), directory, strLen ); watch->mDirName[strLen] = 0; mWatches.Set(watchid, watch); return watchid; }
static void Func ( DistMatrix<T,STAR,STAR>& A, T center, typename Base<T>::type radius ) { const Grid& grid = A.Grid(); const int m = A.Height(); const int n = A.Width(); const int bufSize = m*n; if( grid.InGrid() ) { std::vector<T> buffer( bufSize ); if( grid.Rank() == 0 ) { for( int j=0; j<n; ++j ) for( int i=0; i<m; ++i ) buffer[i+j*m] = center+radius*SampleUnitBall<T>(); } mpi::Broadcast( &buffer[0], bufSize, 0, grid.Comm() ); // Unpack T* localBuffer = A.LocalBuffer(); const int ldim = A.LocalLDim(); #ifdef HAVE_OPENMP #pragma omp parallel for #endif for( int j=0; j<n; ++j ) { const T* bufferCol = &buffer[j*m]; T* col = &localBuffer[j*ldim]; MemCopy( col, bufferCol, m ); } } }
static void Func ( DistMatrix<T,MC,STAR>& A, T center, typename Base<T>::type radius ) { const Grid& grid = A.Grid(); if( grid.InGrid() ) { const int n = A.Width(); const int localHeight = A.LocalHeight(); const int bufSize = localHeight*n; std::vector<T> buffer( bufSize ); // Create random matrix on process column 0, then broadcast if( grid.Col() == 0 ) { for( int j=0; j<n; ++j ) for( int iLocal=0; iLocal<localHeight; ++iLocal ) buffer[iLocal+j*localHeight] = center + radius*SampleUnitBall<T>(); } mpi::Broadcast( &buffer[0], bufSize, 0, grid.RowComm() ); // Unpack T* localBuffer = A.LocalBuffer(); const int ldim = A.LocalLDim(); #ifdef HAVE_OPENMP #pragma omp parallel for #endif for( int j=0; j<n; ++j ) { const T* bufferCol = &buffer[j*localHeight]; T* col = &localBuffer[j*ldim]; MemCopy( col, bufferCol, localHeight ); } } }
LPSTR allocstring(UINT nID,TypeOfResourceHandle bType) { LPSTR szBuffer; szBuffer=new CHAR[STR_LOADSTRINGBUFLEN]; if (szBuffer==NULL) { SetHFCError(HFC_CANNOTALLOCATE); return FALSE; } UINT nDataLen=::LoadStringA(GetResourceHandle(bType),nID,szBuffer,STR_LOADSTRINGBUFLEN); if (nDataLen>=STR_LOADSTRINGBUFLEN-2) { for (DWORD i=2;nDataLen>=i*STR_LOADSTRINGBUFLEN-2;i++) { delete[] szBuffer; szBuffer=new CHAR[i*STR_LOADSTRINGBUFLEN]; nDataLen=::LoadStringA(GetResourceHandle(bType),nID,szBuffer,i*STR_LOADSTRINGBUFLEN); } } char* pText=new char[nDataLen+1]; MemCopy(pText,szBuffer,nDataLen+1); delete[] szBuffer; return pText; }
inline void SortEig( Matrix<R>& w, Matrix<R>& Z ) { #ifndef RELEASE PushCallStack("SortEig"); #endif const int n = Z.Height(); const int k = Z.Width(); // Initialize the pairs of indices and eigenvalues std::vector<internal::IndexValuePair<R> > pairs( k ); for( int i=0; i<k; ++i ) { pairs[i].index = i; pairs[i].value = w.Get(i,0); } // Sort the eigenvalues and simultaneously form the permutation std::sort ( pairs.begin(), pairs.end(), internal::IndexValuePair<R>::Compare ); // Reorder the eigenvectors and eigenvalues using the new ordering Matrix<R> ZPerm( n, k ); for( int j=0; j<k; ++j ) { const int source = pairs[j].index; MemCopy( ZPerm.Buffer(0,j), Z.LockedBuffer(0,source), n ); w.Set(j,0,pairs[j].value); } Z = ZPerm; #ifndef RELEASE PopCallStack(); #endif }
/* Computation of the coefficients alpha that satisfy the equality part of * Maathuis (2003, page 50, eq (5.9)) for all alpha's with positive mass. * The alpha's are a solution of a linear system of equations with * a symmetric (but not positive definite) matrix of coefficients. It is solved using * the function SolveSymmetricLinearSystem(),which uses a LAPACK routine. * * Input: ndata = number of observation rectangles * R = observation rectangles (in canonical form) * w = w[i]=1/max(tol,P[i]), where P[i] is mass in observation rectangle R[i] * m = number of maximal intersections with positive mass * t = upper right corners of maximal intersections with positive mass * i_dummy_mm = dummy array needed in function SolveSymmetricLinearSystem * (this array is allocated in MLE_IQM() to limit number of memory allocations) * d_dummy_mm = right hand side of linear system. * (this array is allocated in MLE_IQM() to limit number of memory allocations) * * Output: alpha = alpha[i] is new probability mass corresponding to t[i]. */ void ComputeAlphasIQM (int ndata, SCanonRect *R, double *w, int m, SIntPoint *t, double alpha[], int *i_dummy_mm, double *d_dummy_mm) { int i, j; double *W; W = Calloc(m*(m+1)/2, double); /* compute matrix a, based on vectors R, w and t */ ComputeW(ndata,R,w,m,t,W); for (i=0; i<m; i++) { d_dummy_mm[i]=0; for (j=0; j<ndata; j++) { if (IsInRectangle(&t[i],&R[j])) d_dummy_mm[i] += w[j]; } } for (i=0; i<m; i++) d_dummy_mm[i] = 2*d_dummy_mm[i]/ndata - 1; SolveSymmetricLinearSystem(W,m,d_dummy_mm,1,i_dummy_mm); MemCopy(alpha,d_dummy_mm,m); Free(W); }
BOOL EXTERN GetCPElementData(CHANDLE CP, SINT Index, MEMPTR lpData, SINT Size) { SINT ElemSize; MEMPTR TagData, ElemData; if (lpData == NULL) { SetCPLastError(CP_NULL_POINTER_ERR); return(FALSE); } if ( !GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData, (LPMEMPTR) &ElemData) ) { return(FALSE); } // Changed by jjia 8/24/95 // ElemData += sizeof(lpcpTagBase); // ElemSize = ui32toSINT( ((lpcpTag)TagData)->size) - // sizeof(lpcpTagBase); ElemData += sizeof(icTagBase) + sizeof(icUInt32Number); ElemSize = ui32toSINT( ((lpcpTag)TagData)->size) - sizeof(icTagBase) - sizeof(icUInt32Number); if(ElemSize > Size ) { SetCPLastError(CP_NO_MEMORY_ERR); return(FALSE); } MemCopy(lpData, ElemData, ElemSize); return(TRUE); }
//*************************************************************** // The difference between GetCPElement and GetCPElementData // is that GetCPElement reads all fields of the element, // including the data tag, reserved fields and element data, // while GetCPElementData only reads the actual data. // Number of bytes that are required to hold the whole data element can be // obtained by calling the function GetCPElementSize(). // The actulal number of data bytes is determined by // the call to GetCPElementDataSize(). //*************************************************************** BOOL EXTERN GetCPElement(CHANDLE CP, SINT Index, MEMPTR lpData, SINT Size) { SINT ElemSize; MEMPTR TagData, ElemData; if (lpData == NULL) { SetCPLastError(CP_NULL_POINTER_ERR); return(FALSE); } if ( !GetCPElementInfo(CP, Index, (LPMEMPTR) &TagData, (LPMEMPTR) &ElemData) ) { return(FALSE); } ElemSize = ui32toSINT( ((lpcpTag)TagData)->size); if(ElemSize > Size ) { SetCPLastError(CP_NO_MEMORY_ERR); return(FALSE); } MemCopy(lpData, ElemData, ElemSize); return(TRUE); }
SINT WriteFloat(MEMPTR lpMem, double dFloat) { char cSign; double dInt ; double dFract ; LONG lFloat ; SINT Res; char TempArray[TempBfSize]; lFloat = (LONG) floor( dFloat * 10000.0 + 0.5); dFloat = lFloat / 10000.0 ; dInt = floor(fabs(dFloat)); dFract = fabs(dFloat) - dInt ; cSign = ' ' ; if ( dFloat < 0 ) { cSign = '-' ; } Res = wsprintf( (LPSTR) TempArray, (LPSTR) "%c%d.%0.4lu ", cSign, (WORD) dInt , (DWORD) (dFract *10000.0) ); MemCopy(lpMem, TempArray, lstrlen(TempArray)); return ( Res ); }
const DistMatrix<T,STAR,STAR>& DistMatrix<T,STAR,STAR>::operator=( const DistMatrix<T,VR,STAR>& A ) { #ifndef RELEASE CallStackEntry entry("[* ,* ] = [VR,* ]"); this->AssertNotLocked(); this->AssertSameGrid( A.Grid() ); #endif const elem::Grid& g = this->Grid(); this->ResizeTo( A.Height(), A.Width() ); if( !this->Participating() ) return *this; const Int p = g.Size(); const Int height = this->Height(); const Int width = this->Width(); const Int localHeightOfA = A.LocalHeight(); const Int maxLocalHeight = MaxLength(height,p); const Int portionSize = mpi::Pad( maxLocalHeight*width ); T* buffer = this->auxMemory_.Require( (p+1)*portionSize ); T* sendBuf = &buffer[0]; T* recvBuf = &buffer[portionSize]; // Pack const Int ALDim = A.LDim(); const T* ABuf = A.LockedBuffer(); PARALLEL_FOR for( Int j=0; j<width; ++j ) MemCopy ( &sendBuf[j*localHeightOfA], &ABuf[j*ALDim], localHeightOfA ); // Communicate mpi::AllGather ( sendBuf, portionSize, recvBuf, portionSize, g.VRComm() ); // Unpack T* thisBuf = this->Buffer(); const Int thisLDim = this->LDim(); const Int colAlignmentOfA = A.ColAlignment(); OUTER_PARALLEL_FOR for( Int k=0; k<p; ++k ) { const T* data = &recvBuf[k*portionSize]; const Int colShift = Shift_( k, colAlignmentOfA, p ); const Int localHeight = Length_( height, colShift, p ); INNER_PARALLEL_FOR for( Int j=0; j<width; ++j ) { T* destCol = &thisBuf[colShift+j*thisLDim]; const T* sourceCol = &data[j*localHeight]; for( Int iLoc=0; iLoc<localHeight; ++iLoc ) destCol[iLoc*p] = sourceCol[iLoc]; } } this->auxMemory_.Release(); return *this; }
SINT WriteObject(MEMPTR lpMem, MEMPTR Obj) { SINT Res; Res = lstrlen(Obj); MemCopy(lpMem, Obj, Res); return( Res ); }