{"action":"created","issue":{"url":"https://api.github.com/repos/wisk/medusa/issues/21","labels_url":"https://api.github.com/repos/wisk/medusa/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/wisk/medusa/issues/21/comments","events_url":"https://api.github.com/repos/wisk/medusa/issues/21/events","html_url":"https://github.com/wisk/medusa/issues/21","id":57615925,"number":21,"title":"Question: FormatDisassembly","user":{"login":"saeschdivara","id":4942808,"avatar_url":"https://avatars.githubusercontent.com/u/4942808?v=3","gravatar_id":"","url":"https://api.github.com/users/saeschdivara","html_url":"https://github.com/saeschdivara","followers_url":"https://api.github.com/users/saeschdivara/followers","following_url":"https://api.github.com/users/saeschdivara/following{/other_user}","gists_url":"https://api.github.com/users/saeschdivara/gists{/gist_id}","starred_url":"https://api.github.com/users/saeschdivara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saeschdivara/subscriptions","organizations_url":"https://api.github.com/users/saeschdivara/orgs","repos_url":"https://api.github.com/users/saeschdivara/repos","events_url":"https://api.github.com/users/saeschdivara/events{/privacy}","received_events_url":"https://api.github.com/users/saeschdivara/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/wisk/medusa/labels/question","name":"question","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-13T15:58:58Z","updated_at":"2015-02-16T14:49:14Z","closed_at":null,"body":"Hey,\r\n\r\nI was trying to print out every single line of the disassembly with formating. It got really slow in the following method:\r\n```c++\r\n// OPTIMIZEME: This function could be very time consumming (use deque?)\r\nbool MappedMemoryArea::_GetPreviousCellOffset(TOffset Offset, TOffset& rPreviousOffset) const\r\n{\r\n  while (Offset != 0x0)\r\n  {\r\n    --Offset;\r\n    if (m_Cells[Offset] != nullptr)\r\n    {\r\n      rPreviousOffset = Offset;\r\n      return true;\r\n    }\r\n  }\r\n\r\n  return false;\r\n}\r\n```\r\nNow my question is if I can just switch the type of m_Cells to a deque or do I need to change something else?"},"comment":{"url":"https://api.github.com/repos/wisk/medusa/issues/comments/74518795","html_url":"https://github.com/wisk/medusa/issues/21#issuecomment-74518795","issue_url":"https://api.github.com/repos/wisk/medusa/issues/21","id":74518795,"user":{"login":"saeschdivara","id":4942808,"avatar_url":"https://avatars.githubusercontent.com/u/4942808?v=3","gravatar_id":"","url":"https://api.github.com/users/saeschdivara","html_url":"https://github.com/saeschdivara","followers_url":"https://api.github.com/users/saeschdivara/followers","following_url":"https://api.github.com/users/saeschdivara/following{/other_user}","gists_url":"https://api.github.com/users/saeschdivara/gists{/gist_id}","starred_url":"https://api.github.com/users/saeschdivara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saeschdivara/subscriptions","organizations_url":"https://api.github.com/users/saeschdivara/orgs","repos_url":"https://api.github.com/users/saeschdivara/repos","events_url":"https://api.github.com/users/saeschdivara/events{/privacy}","received_events_url":"https://api.github.com/users/saeschdivara/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T14:49:13Z","updated_at":"2015-02-16T14:49:13Z","body":"Well, I guess that must be true...\r\nI have updated my code so it may perform better:\r\n```c++\r\nclass MemoryDisAssemblerTask : public QRunnable\r\n{\r\npublic:\r\n\r\n    MemoryDisAssemblerTask(medusa::Medusa * medusa, medusa::Address const rAddress)\r\n        : m_pMedusa(medusa), m_Address(rAddress) {\r\n    }\r\n\r\n    void run()\r\n    {\r\n        medusa::MemoryArea const* rMemArea = m_pMedusa->GetDocument().GetMemoryArea(m_Address);\r\n\r\n        qDebug() << \"Hello world from thread\" << QThread::currentThread();\r\n        qDebug() << m_Address.GetOffset();\r\n\r\n        QString assemblyName = QString::fromStdString( rMemArea->GetName() ) + QString(\".asm\");\r\n\r\n        if (assemblyName.startsWith('.')) {\r\n            assemblyName = QString(\"sec_\") + assemblyName;\r\n        }\r\n\r\n        QFile assemblyFile(assemblyName);\r\n        if (!assemblyFile.open(QIODevice::ReadWrite | QIODevice::Text))\r\n            return;\r\n\r\n        QTextStream out(&assemblyFile);\r\n\r\n        qDebug() << \"Created file at: \" << assemblyFile.fileName();\r\n\r\n        medusa::Address FirstAddr = m_Address;\r\n\r\n        int iLineNumber = 0;\r\n\r\n        std:string MemoryName = rMemArea->GetName();\r\n\r\n        medusa::PrintData Print;\r\n        medusa::FormatDisassembly FmtDisasm(*m_pMedusa, Print);\r\n\r\n        medusa::u32 m_FormatFlags = medusa::FormatDisassembly::ShowAddress |\r\n                            medusa::FormatDisassembly::AddSpaceBeforeXref |\r\n                            medusa::FormatDisassembly::Indent;\r\n\r\n        QString qMemoryName = QString::fromStdString(MemoryName);\r\n\r\n        medusa::TOffset EndOffset = FirstAddr.GetOffset() + rMemArea->GetSize();\r\n        qDebug() << qMemoryName << \" EndOffset: \" << EndOffset;\r\n\r\n\r\n        while (true) {\r\n            qDebug() << qMemoryName << FirstAddr.GetOffset();\r\n\r\n            FmtDisasm(FirstAddr, m_FormatFlags, 1);\r\n\r\n            std::string Line = Print.GetTexts();\r\n            out << QString::fromStdString(Line);\r\n\r\n            iLineNumber++;\r\n\r\n            if (iLineNumber == 1000) {\r\n                iLineNumber = 0;\r\n                assemblyFile.flush();\r\n            }\r\n\r\n            if (FirstAddr.GetOffset() == EndOffset) {\r\n                qDebug() << \"We are at the end of \" << qMemoryName;\r\n                break;\r\n            }\r\n\r\n            if (!m_pMedusa->GetDocument().GetNextAddress(FirstAddr, FirstAddr)) {\r\n                qDebug() << \"Nothing found for \" << qMemoryName;\r\n                break;\r\n            }\r\n        }\r\n\r\n        assemblyFile.flush();\r\n        assemblyFile.close();\r\n    }\r\n\r\nprivate:\r\n    medusa::Address m_Address;\r\n    medusa::Medusa * m_pMedusa;\r\n};\r\n\r\nvoid MainWindow::on_actionSimpleAction_triggered()\r\n{\r\n    _medusa.GetDocument().ForEachMemoryArea([&](medusa::MemoryArea const& rMemArea)\r\n    {\r\n        MemoryDisAssemblerTask *hello = new MemoryDisAssemblerTask(\r\n                    &_medusa,\r\n                    rMemArea.GetBaseAddress()\r\n                    );\r\n\r\n        QThreadPool::globalInstance()->start(hello);\r\n    });\r\n}\r\n```"}}