/* Case 3 - memory definedness doesn't survive remapping */ static void test3() { char *m = mm(0, pgsz * 5, PROT_READ|PROT_WRITE); VALGRIND_MAKE_MEM_UNDEFINED(&m[pgsz], pgsz); mm(&m[pgsz], pgsz, PROT_READ); VALGRIND_CHECK_MEM_IS_DEFINED(&m[pgsz], pgsz); /* OK */ }
/* Case 3 - memory definedness doesn't survive remapping */ static void test3() { char *m = mm(0, pgsz * 5, PROT_READ|PROT_WRITE); VALGRIND_MAKE_WRITABLE(&m[pgsz], pgsz); mm(&m[pgsz], pgsz, PROT_READ); VALGRIND_CHECK_READABLE(&m[pgsz], pgsz); /* OK */ }
int main() { boost::multimethod<void(Base&, Base&)> mm; mm.add_rule<void(Derived1&, Derived2&)>(call_12); mm.add_rule<void(Derived2&, Derived1&)>(call_21); Derived1 d1; Derived2 d2; mm(static_cast<Base&>(d1), static_cast<Base&>(d2)); mm(static_cast<Base&>(d2), static_cast<Base&>(d1)); }
int main(){ Renderer::WindowManager wManager(800, 600, "Renderer Window"); Renderer::initGL(); Renderer::Shader shader("/home/ashutosh/Programming/Projects/Renderer/src/Shaders/vertexShader.sf", "/home/ashutosh/Programming/Projects/Renderer/src/Shaders/fragmentShader.sf"); Renderer::ModelManager mm("/home/ashutosh/Programming/Projects/Renderer/models/nanosuit2.obj"); Renderer::Camera camera(glm::vec3(0.0f, 0.0f, 3.0f)); while (!wManager.doClose()){ Renderer::resetScreen(); shader.Use(); // Set up and pass MVP Matrix glm::mat4 projection = glm::perspective(camera.Zoom, (float)800/(float)600, 0.1f, 100.0f); glm::mat4 view = camera.GetViewMatrix(); glUniformMatrix4fv(glGetUniformLocation(shader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection)); glUniformMatrix4fv(glGetUniformLocation(shader.Program, "view"), 1, GL_FALSE, glm::value_ptr(view)); // Draw the loaded model glm::mat4 model; model = glm::translate(model, glm::vec3(0.0f, -1.75f, 0.0f)); // Translate it down a bit so it's at the center of the scene model = glm::scale(model, glm::vec3(0.2f, 0.2f, 0.2f)); // It's a bit too big for our scene, so scale it down glUniformMatrix4fv(glGetUniformLocation(shader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model)); mm.Draw(shader); wManager.swapBuffers(); } return 0; }
void StackInfo::write(U_8* bytes) { U_8* data = bytes; StackInfo* serializedInfo = (StackInfo*)data; *serializedInfo = *this; serializedInfo->byteSize = getByteSize(); data+=sizeof(StackInfo); MemoryManager mm("DepthInfo"); EntryPtr * entries = new(mm) EntryPtr[hashTableSize]; for(U_32 i = 0; i< hashTableSize; i++) entries[i] = NULL; for(DepthMap::iterator dmit = stackDepthInfo->begin(); dmit != stackDepthInfo->end(); dmit++) { hashSet(entries, dmit->first, hashTableSize, dmit->second, mm); } U_8* next = data + hashTableSize * sizeof(POINTER_SIZE_INT); for(U_32 i = 0; i< hashTableSize; i++) { DepthEntry * e = entries[i]; POINTER_SIZE_INT serializedEntryAddr = 0; if(entries[i]) { serializedEntryAddr = (POINTER_SIZE_INT)next; for(; e != NULL; e = e->next) { DepthEntry* serialized = (DepthEntry*)next; *serialized = *e; next+=sizeof(DepthEntry); serialized->next = e->next ? (DepthEntry*)next : NULL; } } *((POINTER_SIZE_INT*)data)= serializedEntryAddr; data+=sizeof(POINTER_SIZE_INT); } assert(getByteSize() == (POINTER_SIZE_INT) (((U_8*)next) - bytes)); }
void CppEditorDocument::onMimeTypeChanged() { const QString &mt = mimeType(); m_isObjCEnabled = (mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE) || mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)); m_completionAssistProvider = mm()->completionAssistProvider(mt); }
static void test_mipmap_generation(int width, int height, int expectedMipLevelCount, skiatest::Reporter* reporter) { SkBitmap bm; bm.allocN32Pixels(width, height); bm.eraseColor(SK_ColorWHITE); SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); const int mipLevelCount = mm->countLevels(); REPORTER_ASSERT(reporter, mipLevelCount == expectedMipLevelCount); REPORTER_ASSERT(reporter, mipLevelCount == SkMipMap::ComputeLevelCount(width, height)); for (int i = 0; i < mipLevelCount; ++i) { SkMipMap::Level level; REPORTER_ASSERT(reporter, mm->getLevel(i, &level)); // Make sure the mipmaps contain valid data and that the sizes are correct REPORTER_ASSERT(reporter, level.fPixmap.addr()); SkISize size = SkMipMap::ComputeLevelSize(width, height, i); REPORTER_ASSERT(reporter, level.fPixmap.width() == size.width()); REPORTER_ASSERT(reporter, level.fPixmap.height() == size.height()); // + 1 because SkMipMap does not include the base mipmap level. int twoToTheMipLevel = 1 << (i + 1); int currentWidth = width / twoToTheMipLevel; int currentHeight = height / twoToTheMipLevel; REPORTER_ASSERT(reporter, level.fPixmap.width() == currentWidth); REPORTER_ASSERT(reporter, level.fPixmap.height() == currentHeight); } }
// // This method will be used to return information to // Maya. Use the attributes which are outside of // the regular transform attributes to build a new // matrix. This new matrix will be passed back to // Maya. // MMatrix rockingTransformMatrix::asMatrix() const { // Get the current transform matrix MMatrix m = ParentClass::asMatrix(); // Initialize the new matrix we will calculate MTransformationMatrix tm( m ); // Find the current rotation as a quaternion MQuaternion quat = rotation(); // Convert the rocking value in degrees to radians //DegreeRadianConverter conv; //double newTheta = conv.degreesToRadians( getRockInX() ); //quat.setToXAxis( newTheta ); // Apply the rocking rotation to the existing rotation //tm.addRotationQuaternion( quat.x, quat.y, quat.z, quat.w, MSpace::kTransform ); //MVector tv(0,getRockInX(),0); //fm[0][0] =1; fm[0][1] =0; fm[0][2] =0; fm[0][3] =0; //fm[1][0] =0; fm[1][1] =1; fm[1][2] =0; fm[1][3] =0; //fm[2][0] =0; fm[2][1] =0; fm[2][2] =1; fm[2][3] =0; //fm[3][0] =0; fm[3][1] =getRockInX(); fm[3][2] =0; fm[3][3] =1; MMatrix mm(fm); //tm.setTranslation( tv,MSpace::kTransform); tm = mm; // Let Maya know what the matrix should be return tm.asMatrix(); }
int main() { double t_start, t_end; int option; printf("Mit Threads rechnen ? [1 = Ja | 0 = Nein]:"); scanf("%d",&option); if(option == 1) { printf("Wie oft soll verschachtelt werden ?[bis zu 2 mal]:"); scanf("%d",&option); t_start = second(); mm_thread(option); t_end = second(); printf("%f\n", 2.0 * pow(m_size, 3) / (t_end - t_start) / 1000000000); } else { printf("Wie oft soll verschachtelt werden ?[bis zu 2 mal]:"); scanf("%d",&option); t_start = second(); mm(option); t_end = second(); printf("%f\n", 2.0 * pow(m_size, 3) / (t_end - t_start) / 1000000000); } return 0; }
template <typename F> void drawLevels(SkCanvas* canvas, const SkBitmap& baseBM, F func) { SkScalar x = 4; SkScalar y = 4; SkPixmap prevPM; baseBM.lockPixels(); baseBM.peekPixels(&prevPM); SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(baseBM, nullptr)); int index = 0; SkMipMap::Level level; SkScalar scale = 0.5f; while (mm->extractLevel(SkSize::Make(scale, scale), &level)) { SkBitmap bm = func(prevPM, level.fPixmap); DrawAndFrame(canvas, bm, x, y); if (level.fPixmap.width() <= 2 || level.fPixmap.height() <= 2) { break; } if (index & 1) { x += level.fPixmap.width() + 4; } else { y += level.fPixmap.height() + 4; } scale /= 2; prevPM = level.fPixmap; index += 1; } }
boost::shared_ptr<ecto::module_<T> > inspect(boost::python::tuple args, boost::python::dict kwargs) { typedef ecto::module_<T> module_t; namespace bp = boost::python; //SHOW(); boost::shared_ptr<module_t> mm(new module_t()); ecto::module * m = mm.get(); m->declare_params(); bp::list l = kwargs.items(); for (int j = 0; j < bp::len(l); ++j) { bp::object key = l[j][0]; bp::object value = l[j][1]; std::string keystring = bp::extract<std::string>(key); std::string valstring = bp::extract<std::string>(value.attr("__repr__")()); m->parameters.at(keystring).set(value); } m->declare_io(); return mm; }
int main(int argc, const char *argv[]) { int i, j, iret; double first[SIZE][SIZE]; double second[SIZE][SIZE]; double multiply[SIZE][SIZE]; double dtime; for (i = 0; i < SIZE; i++) { // rows in first for (j = 0; j < SIZE; j++) { // columns in first first[i][j] = i + j; second[j][i] = i - j; multiply[i][j] = 0.0; } } papi_init(atoi(argv[1])); papi_start(); iret = mm(first, second, multiply); papi_stop(); double check = 0.0; for (i = 0; i < SIZE; i++) { for (j = 0; j < SIZE; j++) { check += multiply[i][j]; } } fprintf(stderr, "check %le \n", check); return iret; }
void RunnerView::readSocket() { // qDebug() << "RunnerView::readSocket - bytes available:" << m_socket->bytesAvailable(); Message* m(Message::read(m_socket)); if (m) { switch (m->type()) { case MessageType::Undefined : qWarning("RunnerView::readSocket - message type: Undefined"); break; case MessageType::CloneRequest : { handleCloneRequest(); break; } case MessageType::CloneData : { CloneDataMessage* cdm(dynamic_cast<CloneDataMessage*>(m)); handleCloneData(cdm); break; } case MessageType::Mouse : { MouseMessage* mm(dynamic_cast<MouseMessage*>(m)); handleMouse(mm); break; } case MessageType::Close : quitApplication(); break; default : { qDebug() << "RunnerView::readSocket - message:" << *m; break; } } delete m; } if (m_socket->bytesAvailable()) { QMetaObject::invokeMethod(this, "readSocket", Qt::QueuedConnection); } }
int main() { auto print = [&](unsigned char* c) { for (int i = 16;i < 163;++i) { printf(",0x%02x",(unsigned int) c[i]); if (i % 8 == 7) printf("\n"); } printf("\n"); }; crypto_box(c,m,163,nonce,bobpk,alicesk); print(c); int constexpr s = 163; Message mm(m , s); crypto_array<u8,s> mc; auto n = Nonce::wrap(nonce); auto pk = Key::wrap(bobpk); auto sk = Key::wrap(alicesk); auto out = Message(mc.p(), s); crypto_box(out, mm, n, pk, sk); print(mc.p()); return 0; }
int main( int argc, const char* argv[] ) { papi_init(); int i,j,iret,w; for(w = 320;w<640;w+=64){ SIZE = w; double first[SIZE][SIZE]; double second[SIZE][SIZE]; double multiply[SIZE][SIZE]; double dtime; for (i = 0; i < SIZE; i++) { //rows in first for (j = 0; j < SIZE; j++) { //columns in first first[i][j]=i+j; second[i][j]=i-j; multiply[i][j]=0.0; } } papi_start(); iret=mm(first,second,multiply); papi_stop((w-320)/64); } print_papi_results(); return iret; }
int main( int argc, const char* argv[] ) { int i,j,iret; double first[SIZE][SIZE]; double second[SIZE][SIZE]; double multiply[SIZE][SIZE]; double dtime; for (i = 0; i < SIZE; i++) { //rows in first for (j = 0; j < SIZE; j++) { //columns in first first[i][j]=i+j; second[i][j]=i-j; } } dtime = dclock(); iret=mm(first,second,multiply); dtime = dclock()-dtime; printf( "Time: %le \n", dtime); fflush( stdout ); double check=0.0; for(i=0;i<SIZE;i++){ for(j=0;j<SIZE;j++){ check+=multiply[i][j]; } } printf("check %le \n",check); fflush( stdout ); return iret; }
MemoryMatrix DataGrid::toVector() const { MemoryMatrix mm(width() * height()); unsigned int i = 0; for (int x = 0; x < width(); x++) for (int y = 0; y < height(); y++) mm.set(i++, 0, at(x, y)); return mm; }
void test_message_copy_operations() { azmq::message m(42); azmq::message mm(m); BOOST_ASSERT(m.size() == mm.size() && mm.size() == 42); azmq::message mmm = m; BOOST_ASSERT(m.size() == mmm.size() && mmm.size() == 42); }
void parallelOperation(double **a, double **b, double **c, int size, int operation) { int i; struct work_struct *jobs[CPUCORES]; aa = a; bb = b; cc = c; matrixSize = size; for (i = 0; i < CPUCORES; i++) { jobs[i] = malloc(sizeof(struct work_struct)); if (jobs[i] == NULL) { perror(NULL); exit(1); } jobs[i]->id = i; } job_init(); switch(operation){ case MULTIPLY:{ // printf("Multiply[%d]: ", size); for (i = 1; i < CPUCORES; i++) job_create(mm, jobs[i], 0); mm(jobs[0]); }break; case VECTOR:{ // printf("Vector[%d]: ", size); for (i = 1; i < CPUCORES; i++) job_create(mv, jobs[i], 0); mv(jobs[0]); }break; case ADD:{ // printf("Add[%d]: ", size); for (i = 1; i < CPUCORES; i++) job_create(add, jobs[i], 0); add(jobs[0]); }break; case SCALE:{ // printf("Scale[%d]: ", size); for (i = 1; i < CPUCORES; i++) job_create(scale, jobs[i], 0); scale(jobs[0]); }break; } for (i = 1; i < CPUCORES; i++) job_join(jobs[i]); // printf("\n"); }
obj_t::obj_t( const char * objname ) { // long name fullpath = realname( objname ); // model handle const char * shortname = strip_path_and_extension( objname ); name = copy_string( shortname ); // memory map file mmfile_t mm( fullpath ); index = 0; size = mm.size; data = mm.data; while ( index < size ) { strip_white_space(); switch( data[i] ) { case 'm': if ( check_name( "mtllib" ) ) consume_line(); break; case 'u': if ( check_name( "usemtl" ) ) consume_line(); break; case 'g': consume_line(); break; case '#': strip_white_space(); break; case 'v': if ( check_name( "vn" ) ) add_normal(); else if ( check_name( "vt" ) ) add_texcoord(); else if ( data[index+1] == ' ' ) add_vertex(); else core.warn( "obj_t: straggling v in objfile: %s", name ); break; case 'f': if ( data[index+1] == ' ' ) add_face(); break; case 's': default: ++index; break; } } }
void AbstractTemplateModel::render(QPainter *painter) { Q_ASSERT(painter != nullptr); device = painter->device(); QMargins paperMargins; QMargins pageMargins; paperMargins += mm(5); pageMargins += mm(5); QRect rect = QRect(0, 0, width(), height()).marginsRemoved(paperMargins); const QPoint center = rect.center(); cutHerePen.setWidthF(mm(penWidthMM)); painter->save(); painter->setRenderHint(QPainter::Antialiasing); painter->setPen(cutHerePen); painter->setBrush(Qt::NoBrush); painter->translate(cutPenWidth() / 2, cutPenWidth() / 2); // Horizontal and vertical center line painter->drawLine(center.x(), rect.y(), center.x(), rect.y() + rect.height() - cutPenWidth()); painter->drawLine(rect.x(), center.y(), rect.x() + rect.width() - cutPenWidth(), center.y()); // Printable area painter->drawRect(rect.x(), rect.y(), rect.width() - cutPenWidth(), rect.height() - cutPenWidth()); QRect page = QRect(rect.topLeft(), center); for (int y = rect.y(); y < rect.height() - 1; y += page.height()) { for (int x = rect.x(); x < rect.width() - 1; x += page.width()) { page.moveTo(x, y); painter->save(); paintPage(painter, page.marginsRemoved(pageMargins)); painter->restore(); } } painter->restore(); }
void testObj::test<2>(void) { UniqueDescriptor fd( open("/etc/fstab", O_RDONLY) ); ensure("cannot open test file", fd.get() != -1 ); MappedMem<char> mm(10, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd.get(), 0); // test mv-ctor MappedMem<char> other( std::move(mm) ); ensure("ownership not transffered", mm.mem() == nullptr ); ensure("ownership lost", other.mem() != nullptr ); }
void testObj::test<1>(void) { UniqueDescriptor fd( open("/etc/fstab", O_RDONLY) ); ensure("cannot open test file", fd.get() != -1 ); MappedMem<char> mm(10, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd.get(), 0); ensure_equals("invalid map size", mm.size(), 10); ensure("memory is NULL", mm.mem() != nullptr ); for(size_t i=0; i<mm.size(); ++i) ensure("char is notnprintable - invalid mapping?", isprint( mm.mem()[i] ) ); }
void test_message_buffer_operations() { azmq::message mm(42); // implicit cast to const_buffer boost::asio::const_buffer b = mm; BOOST_ASSERT(boost::asio::buffer_size(b) == mm.size()); // implicit cast to mutable_buffer boost::asio::mutable_buffer bb = mm; BOOST_ASSERT(boost::asio::buffer_size(bb) == mm.size()); }
void binary_reader::tests_::test_market_message() { static const std::string test_file_name = BINARY_DIR "/test_out.txt"; BOOST_CHECK_NO_THROW( market_message( 1, 2, "hello world" ) ); { std::ofstream out( test_file_name.c_str(), std::ios_base::binary ); market_message mm( 1ul,2ul, "hello world" ); mm.write( out ); } { std::ifstream in( test_file_name.c_str(), std::ios_base::binary ); market_message mm( in ); BOOST_CHECK_EQUAL( mm.type(), 1ul ); BOOST_CHECK_EQUAL( mm.time(), 2ul ); BOOST_CHECK_EQUAL( memcmp( mm.msg(), "hello world", 10ul ), 0 ); } { std::ofstream out( test_file_name.c_str(), std::ios_base::binary ); market_message mm( 1ul,2ul, "hello world" ); mm.write( out ); } { std::ofstream out( test_file_name.c_str(), std::ios_base::binary ); for( boost::uint32_t i = 0 ; i < 100000 ; ++i ) { const std::string string = "1234"; market_message mm( 1ul, i , string.c_str() ); mm.write( out ); } } { std::ifstream in( test_file_name.c_str(), std::ios_base::binary ); size_t amount = 0; while ( !in.eof() ) { ++amount; market_message mm( in ); } BOOST_CHECK_EQUAL( amount, 100001ul ); } boost::filesystem::remove( test_file_name ); }
/* * computes and returns dot procuct of two matrices */ float * multiply(float *m1, int dim11, int dim12, float *m2, int dim21, int dim22) { float *m3; if (dim12 != dim21) return NULL; m3 = (float*)malloc(sizeof(float) * dim11 * dim22); if (mode == 'c') mm(m1, m2, m3, dim11, dim12, dim22); else if (mode == 'g') mm_cuda(m1, m2, m3, dim11, dim12, dim22); else if (0 && dim11 * dim22 < GPU_THRESHOLD) mm(m1, m2, m3, dim11, dim12, dim22); else mm_cuda(m1, m2, m3, dim11, dim12, dim22); return m3; }
void mrb_free_context(mrb_state *mrb, struct mrb_context *ctx) { if (!ctx) return; MemManager &mm(mrb->gc()); mm._free(ctx->m_stbase); mm._free(ctx->cibase); mm._free(ctx->rescue); mm._free(ctx->m_ensure); mm._free(ctx); }
/* Case 4 - mprotect doesn't affect addressability */ static void test4() { char *m = mm(0, pgsz * 5, PROT_READ|PROT_WRITE); mprotect(m, pgsz, PROT_WRITE); VALGRIND_CHECK_READABLE(m, pgsz); /* OK */ m[44] = 'y'; /* OK */ mprotect(m, pgsz*5, PROT_NONE); m[55] = 'x'; /* permission fault, but no tool complaint */ }
bool WinMetaFileDraw::Create(HDC hdc, int cx, int cy, const char *app, const char *name, const char *file) { if(handle) Close(); String s; if(app) s.Cat(app); s.Cat('\0'); if(name) s.Cat(name); s.Cat('\0'); bool del = false; if(!hdc) { hdc = ::GetWindowDC((HWND) NULL); del = true; } size = Size(iscale(cx, 2540, 600), iscale(cy, 2540, 600)); Rect r = size; HDC mfdc = ::CreateEnhMetaFile(hdc, file, r, name || app ? (const char *)s : NULL); if(!mfdc) return false; Size px(max(1, ::GetDeviceCaps(mfdc, HORZRES)), max(1, ::GetDeviceCaps(mfdc, VERTRES))); Size mm(max(1, ::GetDeviceCaps(mfdc, HORZSIZE)), max(1, ::GetDeviceCaps(mfdc, VERTSIZE))); Attach(mfdc); Init(); pixels = false; ::SetMapMode(handle, MM_ANISOTROPIC); ::SetWindowOrgEx(handle, 0, 0, 0); ::SetWindowExtEx(handle, 600, 600, 0); ::SetViewportOrgEx(handle, 0, 0, 0); ::SetViewportExtEx(handle, px.cx * 254 / (10 * mm.cx), px.cy * 254 / (10 * mm.cy), 0); ::SelectClipRgn(mfdc, NULL); ::IntersectClipRect(mfdc, 0, 0, cx, cy); if(del) { ::ReleaseDC((HWND) NULL, hdc); hdc = NULL; } actual_offset = Point(0, 0); printer = false; pixels = false; actual_offset = Point(0, 0); device = -1; aborted = false; palette = false; backdraw = true; return true; }
/* Case 2 - unmapped memory is unaddressable+undefined */ static void test2() { char *m = mm(0, pgsz * 5, PROT_READ|PROT_WRITE); VALGRIND_CHECK_READABLE(m, pgsz*5); /* all OK */ munmap(&m[pgsz*2], pgsz); VALGRIND_CHECK_READABLE(&m[pgsz*2], pgsz); /* undefined */ /* XXX need an memcheck/addrcheck request to test addressability */ m[pgsz*2] = 'x'; /* unmapped fault */ }