void code(lzma_stream &stream, std::istream &in, std::ostream &out) { std::vector<char> inbuf(chunksize, 0), outbuf(chunksize, 0); while (true) { stream.next_in = reinterpret_cast<uint8_t *>(&inbuf[0]); in.read(&inbuf[0], inbuf.size()); std::streamsize insize = in.gcount(); stream.avail_in = insize; stream.total_in = 0; do { stream.total_out = 0; stream.next_out = reinterpret_cast<uint8_t *>(&outbuf[0]); stream.avail_out = outbuf.size(); lzma_ret retval = lzma_code(&stream, insize == 0 ? LZMA_FINISH : LZMA_RUN); if (retval == LZMA_STREAM_END) { if (stream.avail_in != 0) throw compress_error{"Unprocessed input remaining in stream"}; out.write(&outbuf[0], stream.total_out); lzma_end(&stream); return; } if (retval != LZMA_OK) throw compress_error{"Stream encoding failed"}; //std::cout << "Retrieved " << stream.total_in << " bytes and output " << stream.total_out << " bytes\n"; out.write(&outbuf[0], stream.total_out); } while (stream.total_out > 0); } }
// 返回解压后的大小 static size_t enet_simple_decompress(void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit) { qDebug()<<inLimit<<outLimit; QByteArray inbuf((const char*)inData, inLimit); QByteArray outbuf = qUncompress(inbuf); memcpy(outData, outbuf.data(), outbuf.length()); return outbuf.length(); return 0; }
CFunction * CFunctionDB::dBLoad(const std::string & functionName) { CFunction Function("NoName", &mLoadedFunctions); CFunction * pFunction = NULL; if (mFilename == "") return NULL; CReadConfig inbuf(mFilename); while (functionName != Function.getObjectName()) { Function.cleanup(); Function.load(inbuf); } switch (Function.getType()) { case CFunction::Base: pFunction = new CFunction(Function); break; case CFunction::MassAction: pFunction = new CMassAction(Function.isReversible()); break; case CFunction::PreDefined: case CFunction::UserDefined: pFunction = new CKinFunction(Function, &inbuf); break; case CFunction::Expression: fatalError(); //disabled //pFunction = new CUDFunction(Function); break; default: fatalError(); } if (!mLoadedFunctions.add(pFunction)) { pdelete(pFunction); // We ignore: // CCopasiVector (2): Object '%s' allready exists. if ((MCCopasiVector + 2) != CCopasiMessage::getLastMessage().getNumber()) pFunction = mLoadedFunctions[Function.getObjectName()]; } return pFunction; }
// --------------------------------------------------------- // CWlanMgmtCommandHandler::GetLastRCPI // Get the signal quality of the last received packet. // --------------------------------------------------------- // void CWlanMgmtCommandHandler::GetLastRCPI( TUint32& aRCPI ) { DEBUG( "CWlanMgmtCommandHandler::GetLastRCPI()" ); TGetLastRcpiMsg msg; msg.hdr.oid_id = E802_11_GET_LAST_RCPI; TPckg<TGetLastRcpiMsg> outbuf( msg ); TPckg<TUint32> inbuf( aRCPI ); iBuffer.Set( inbuf ); TInt err = iChannel.ManagementCommand( outbuf, &iBuffer, &iStatus ); if( err ) { DEBUG1( "ERROR calling RWlanLogicalChannel::ManagementCommand(): %d", err ); TRequestStatus* status = &iStatus; User::RequestComplete( status, err ); } SetActive(); }
// --------------------------------------------------------- // CWlanMgmtCommandHandler::GetPacketStatistics // --------------------------------------------------------- // void CWlanMgmtCommandHandler::GetPacketStatistics( TStatisticsResponse& aStatistics ) { DEBUG( "CWlanMgmtCommandHandler::GetPacketStatistics()" ); TGetFrameStatisticsMsg msg; msg.hdr.oid_id = E802_11_GET_FRAME_STATISTICS; TPckg<TGetFrameStatisticsMsg> outbuf( msg ); TPckg<TStatisticsResponse> inbuf( aStatistics ); iBuffer.Set( inbuf ); TInt err = iChannel.ManagementCommand( outbuf, &iBuffer, &iStatus ); if( err ) { DEBUG1( "ERROR calling RWlanLogicalChannel::ManagementCommand(): %d", err ); TRequestStatus* status = &iStatus; User::RequestComplete( status, err ); } SetActive(); }
int main() { pcg32_k64 rng; std::istringstream inbuf(saved_state); inbuf >> rng; std::clog << inbuf.str() << "\n\n"; if (inbuf.fail()) abort(); constexpr size_t BUFFER_SIZE = 1024ull * 128ull; uint32_t buffer[BUFFER_SIZE]; constexpr size_t ROUNDS = 215 * 1073741824ull / sizeof(buffer); for (size_t i = 0; i < ROUNDS; ++i) { for (auto& v : buffer) v = rng(); write(1, (void*) buffer, sizeof(buffer)); } return 0; }
int main(int argc, char *argv[]) { const int test_size = 128; std::random_device rd; std::seed_seq s{ rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd() }; std::mt19937 mt(s); EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu(); CLKernel *kern = cl->buildKernel("test.cl", "test"); std::vector<uint32_t> inbuf(test_size*4), outbuf(test_size), compare(test_size); std::generate(inbuf.begin(), inbuf.end(), mt); std::cout << "Running CL implementation" << std::endl; kern->in(inbuf.size(), &inbuf[0]); kern->out(outbuf.size(), &outbuf[0]); size_t global_size[] = { test_size }; kern->run(1, global_size, nullptr); delete kern; std::cout << "Running local implementation" << std::endl; for (int i = 0; i < compare.size(); ++i) { compare[i] = inbuf[i] ^ inbuf[i + 1] ^ inbuf[i + 2] ^ inbuf[i + 3]; } std::cout << "Comparing CL test with local implementation" << std::endl; for (int i = 0; i < compare.size(); ++i) { if (outbuf[i] != compare[i]) { std::cout << "Error in index " << i << " " << outbuf[i] << " != " << compare[i] << std::endl; } } return 0; }
int main (int argc, char **argv) try { edmplugin::PluginManager::configure(edmplugin::standard::config()); if (argc < 3) { std::cerr << "usage: " << argv[0] << " INFILE OUTFILE...\n"; return EXIT_FAILURE; } std::shared_ptr<Storage> is; std::vector<std::unique_ptr<Storage> > os(argc-2); std::vector<std::thread> threads; bool readThreadActive = true; bool writeThreadActive = true; IOOffset size = -1; StorageFactory::getToModify ()->enableAccounting(true); bool exists = StorageFactory::getToModify ()->check(argv [1], &size); std::cerr << "input file exists = " << exists << ", size = " << size << "\n"; if (! exists) return EXIT_SUCCESS; try { is = StorageFactory::getToModify ()->open (argv [1]); if (readThreadActive) threads.emplace_back(&readThread,is.get()); } catch (cms::Exception &e) { std::cerr << "error in opening input file " << argv[1] << ":\n" << e.explainSelf() << std::endl; return EXIT_FAILURE; } // open output files and create threads, one thread per output for (int i=0; i < argc-2; i++) try { os[i]= StorageFactory::getToModify ()->open (argv[i+2], IOFlags::OpenWrite | IOFlags::OpenCreate | IOFlags::OpenTruncate); if (writeThreadActive) threads.emplace_back(&writeThread,os[i].get()); } catch (cms::Exception &e) { std::cerr << "error in opening output file " << argv[i+2] << ":\n" << e.explainSelf() << std::endl; return EXIT_FAILURE; } std::vector<char> inbuf (1048576); std::vector<char> outbuf(1048576); IOSize n; while ((n = readThreadActive ? inbox.get(inbuf) : is->read(&inbuf[0],inbuf.size()))) { //free reading thread inbuf.swap(outbuf); // wait threads have finished to write // drop buffer in thread if (writeThreadActive) { if (! dropbox.set(outbuf,n)) break; } else for (size_t i = 0; i < os.size(); i++) os[i]->write(&outbuf[0],n); } std::cout << "main end reading" << std::endl; // tell thread to end inbuf.clear(); if (readThreadActive) inbox.get(inbuf); if (writeThreadActive) dropbox.set(outbuf, 0); if (writeThreadActive || readThreadActive) { for(auto& t: threads) { t.join(); } } std::cout << StorageAccount::summaryText(true) << std::endl; return EXIT_SUCCESS; } catch(cms::Exception const& e) { std::cerr << e.explainSelf() << std::endl; return EXIT_FAILURE; } catch(std::exception const& e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; }