I try to connect c++ to matlab for figure function. for the example
Engine *m_pEngine;
m_pEngine = engOpen("null"); //open matlab engine
const int arraysize = 1000;
const double degTorad = .0174;
double SinArray[arraysize];
double CosArray[arraysize];
double Degrees[arraysize];
for (int iii = 0; iii < arraysize; iii++)
{
Degrees[iii] = iii;//gets the degree
SinArray[iii] = sin(iii*degTorad);
CosArray[iii] = cos(iii*degTorad);
}
cout << "Example 1 or 2?"<<"\n";
char Sim = '1';
cin >> Sim;
// example 1 below
// we will pass an entire array to be plotted
if (Sim == '1')
{
mxArray* SIN = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
memcpy((void *)mxGetPr(SIN), (void *)SinArray, sizeof(double)*arraysize);
engPutVariable(m_pEngine, "SinGraph", SIN);
mxArray* COS = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
memcpy((void *)mxGetPr(COS), (void *)CosArray, sizeof(double)*arraysize);
engPutVariable(m_pEngine, "CosGraph", COS);
mxArray* DEG = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
memcpy((void *)mxGetPr(DEG), (void *)Degrees, sizeof(double)*arraysize);
engPutVariable(m_pEngine, "Degrees", DEG);
engEvalString(m_pEngine, "figure('units','normalized','outerposition',(0 0 1 1))"); //opens up matlab figure window
engEvalString(m_pEngine, "plot(Degrees,SinGraph,'r',Degrees,CosGraph,'b'),grid minor,title('our Matlab Plot')");
system("pause");
}
it runs well and I can get the correct results. that means the environment setting in my computer is correct. but when run the code below:
for (int i = 0; i < 141; i++)
{
x.push_back(((-141 / 2 + 1 - 1+i)*0.0003));
y.push_back(((-141 / 2 + 1 - 1+i)*0.0003));
}
engine *m_pEngine;
m_pEngine = engOpen("null"); //open matlab engine
mxArray *xxx = mxCreateDoubleMatrix(1, 141, mxREAL);
memcpy((void*)mxGetM(xxx), &x, sizeof(double)*x.size());
engPutVariable(m_pEngine, "x", xxx);
mxArray *yyy = mxCreateDoubleMatrix(1, 141, mxREAL);
memcpy((void*)mxGetM(yyy), &y, sizeof(double)*y.size());
engPutVariable(m_pEngine, "y", yyy);
it breaks for: Unhandled exception at 0x00007FFFB193AA69 (msvcr120d.dll) in PlanarforwardC.exe: 0xC0000005: Access violation writing location 0x0000000000000001.
and it also says that:
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwcholmod.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\graphics_util.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwplatform_res.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Windows\System32\msimg32.dll'. Symbols loaded.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwamd.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwcolamd.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwblas.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwlapack.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. Symbols loaded.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwbinder.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwompwrapper.dll'. Cannot find or open the PDB file.
DBGHELP: Symbol Search Path: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\m_interpreter.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\dll\m_interpreter.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\symbols\dll\m_interpreter.pdb - file not found
DBGHELP: y:\R2012bd\build\matlab\bin\win64\m_interpreter.pdb - file not found
DBGHELP: m_interpreter - export symbols
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\msvcr90.amd64.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\dll\msvcr90.amd64.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\symbols\dll\msvcr90.amd64.pdb - file not found
DBGHELP: msvcr90.amd64.pdb - file not found
memcpy((void*)mxGetM(xxx), &x, sizeof(xx));
I also tried to find the solution and use double xx[141]and double yy[141]replace vector x and vector y.
mxArray *xxx = mxCreateDoubleMatrix(1, num_x, mxREAL);
memcpy((void*)mxGetM(xxx), (void*)xx, sizeof(xx));
engPutVariable(m_pEngine, "x", xxx);
mxArray *yyy = mxCreateDoubleMatrix(1, num_x, mxREAL);
memcpy((void*)mxGetM(yyy), (void*)yy, sizeof(double)*y.size());
engPutVariable(m_pEngine, "y", yyy);
it still didn't work.
can anyone give me some suggestions about this? I tested line by line and the problem is in :
many thanks
mxGetM returns the size of the array. This size is used as an pointer in memcpy, which definitely leads to an invalid memory address.
Related
I am fairly new to Boost. I am using the Boost 1.72.0. I am trying to explore boost::asio::thread_pool and posting tasks to it as per the documentation. I try to post a continuation to the posted task as follows:
Using boost::launch::executor policy:
fut.then(boost::launch::executor, [](boost::future<void> res) {
std::thread::id this_id = std::this_thread::get_id();
std::cout << "\nThread Id:" << this_id;
std::cout << "\nThen Task: Start";
});
In the above case the code crashes as follows.
> ThreadPool_Boost.exe!boost::executors::executor_ref<boost::executors::executor>::submit(boost::detail::nullary_function<void __cdecl(void)> && closure={...}) Line 73 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::executors::executor::submit(boost::detail::run_it<boost::detail::continuation_shared_state<boost::future<void>,void,void <lambda>(boost::future<void>),boost::detail::shared_state<void>>> &&) Line 107 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::detail::future_executor_continuation_shared_state<boost::future<void>,void,void <lambda>(boost::future<void>)>::launch_continuation() Line 4711 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::detail::shared_state<void>::do_continuation(boost::unique_lock<boost::mutex> & lock={...}) Line 853 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::detail::shared_state_base::mark_finished_internal(boost::unique_lock<boost::mutex> &) Line 345 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::detail::shared_state<void>::mark_finished_with_result_internal(boost::unique_lock<boost::mutex> &) Line 857 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::detail::shared_state<void>::mark_finished_with_result() Line 864 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::detail::task_shared_state<void <lambda>(void),void __cdecl(void)>::do_run() Line 3423 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::detail::task_base_shared_state<void __cdecl(void)>::run() Line 2995 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::packaged_task<void __cdecl(void)>::operator()() Line 3781 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::asio::asio_handler_invoke<boost::packaged_task<void __cdecl(void)>>(boost::packaged_task<void __cdecl(void)> & function, ...) Line 70 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost_asio_handler_invoke_helpers::invoke(boost::packaged_task<void __cdecl(void)> &) Line 37 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::asio::system_executor::dispatch(boost::packaged_task<void __cdecl(void)> &&) Line 39 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::asio::detail::work_dispatcher<boost::packaged_task<void __cdecl(void)>>::operator()() Line 59 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::asio::asio_handler_invoke<boost::asio::detail::work_dispatcher<boost::packaged_task<void __cdecl(void)>>>(boost::asio::detail::work_dispatcher<boost::packaged_task<void __cdecl(void)>> & function={...}, ...) Line 69 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost_asio_handler_invoke_helpers::invoke(boost::asio::detail::work_dispatcher<boost::packaged_task<void __cdecl(void)>> &) Line 37 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::asio::detail::executor_op<boost::asio::detail::work_dispatcher<boost::packaged_task<void __cdecl(void)>>,std::allocator<void>,boost::asio::detail::scheduler_operation>::do_complete(void * owner=0x011a61d8, boost::asio::detail::scheduler_operation * base=0x011af1c8, const boost::system::error_code & __formal={...}, unsigned int __formal=0x00000000) Line 70 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::asio::detail::scheduler_operation::complete(void *) Line 40 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::asio::detail::scheduler::do_run_one(boost::asio::detail::conditionally_enabled_mutex::scoped_lock & lock={...}, boost::asio::detail::scheduler_thread_info & this_thread={...}, const boost::system::error_code & ec={...}) Line 449 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::asio::detail::scheduler::run(boost::system::error_code & ec={...}) Line 200 C++ Symbols loaded.
[Inline Frame] ThreadPool_Boost.exe!boost::asio::thread_pool::thread_function::operator()() Line 33 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::asio::detail::win_thread::func<boost::asio::thread_pool::thread_function>::run() Line 123 C++ Symbols loaded.
ThreadPool_Boost.exe!boost::asio::detail::win_thread_function(void * arg=0x011a65a0) Line 128 C++ Symbols loaded.
ucrtbase.dll!767b38df() Unknown Non-user code. Symbol loading disabled by Include/Exclude setting.
ucrtbase.dll![Frames below may be incorrect and/or missing, no symbols loaded for ucrtbase.dll] Unknown No symbols loaded.
kernel32.dll!77b36359() Unknown Non-user code. Symbol loading disabled by Include/Exclude setting.
ntdll.dll!77d88944() Unknown Non-user code. Symbol loading disabled by Include/Exclude setting.
ntdll.dll!77d88914() Unknown Non-user code. Symbol loading disabled by Include/Exclude setting.
Using the variant of 'then' where we can mention executor:
fut.then(pool.get_executor(), [](boost::future<void> res) { /* <---- This is line 62 */
std::thread::id this_id = std::this_thread::get_id();
std::cout << "\nThread Id:" << this_id;
std::cout << "\nThen Task: Start";
});
The above code fails to compile saying the following:
1>C:\Users\shtrived\Desktop\AsyncTask\ThreadPool_Boost\Demo.cpp(62,5): error C2664: 'boost::future<void> boost::future<void>::then<boost::asio::thread_pool::executor_type,main::<lambda_c8a45d8f92e13883b6218f06c9a06a8d>>(Ex &,F &&)': cannot convert argument 1 from 'boost::asio::thread_pool::executor_type' to 'boost::launch'
1> with
1> [
1> Ex=boost::asio::thread_pool::executor_type,
1> F=main::<lambda_c8a45d8f92e13883b6218f06c9a06a8d>
1> ]
Question:
Why the above run time and compile time errors ?
How to post the continuation correctly to the thread pool only ?
Full Sample Code:
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
#define BOOST_THREAD_PROVIDES_VARIADIC_THREAD
#define BOOST_ERROR_CODE_HEADER_ONLY
#define BOOST_THREAD_PROVIDES_FUTURE_UNWRAP
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#define BOOST_RESULT_OF_USE_DECLTYPE
#define BOOST_THREAD_VERSION 4
#define BOOST_THREAD_PROVIDES_EXECUTORS //on including this we start getting build errors
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>
#include<iostream>
#include<thread>
#include<stdexcept> //only for testing
#include<vector>
//#include<boost/asio/executor.hpp>
#include<boost/asio.hpp>
int main()
{
boost::asio::thread_pool pool(1);
//This is the first function that we want to run on the thread pool
auto func = []() {
cout << "\nTask in progress";
std::thread::id this_id = std::this_thread::get_id();
cout << "\nThread Id:" << this_id << " Task 1: Just a cout";
};
//Make a packaged task with the above function
boost::packaged_task<void()> task(std::move(func));
//Get the future from the packaged task
boost::future<void> fut = task.get_future();
//Post the task into the thread pool
boost::asio::post(pool, std::move(task));
/*
* We want to run the continuation in the same thread pool
*/
fut.then(pool.get_executor(), [](boost::future<void> res) {
std::thread::id this_id = std::this_thread::get_id();
std::cout << "\nThread Id:" << this_id;
std::cout << "\nThen Task: Start";
});
pool.join();
cout << "\nJoin Complete";
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I will link the classes and output from execution below.
The problem is, the std::map is iterating through and the pointer stored in the second which is of type void* is not deleting from the heap and freeing. The std::map iterated through in the void ShutDown(void); method of the class Engine which is called in the destructor for that class.
I will post the code and output from execution.
Engine header file:
#ifndef _TEST_ENGINE_H_
#define _TEST_ENGINE_H_
#include "test_graphics_system.h"
#include <iostream>
#include <map>
namespace Core {
enum class EngineStatus {
Invalid,
Constructing,
Setup,
Running,
ShutDown,
Destroying
};
class Engine
{
public:
Engine(void);
~Engine(void);
template<class T> T * GetSystem(SystemType systemType)
{
if (mSystems[systemType])
{
return (T*)mSystems[systemType];
}
else
{
std::wcout << "System doe not exist" << std::endl;
}
return nullptr;
}
int Run(void);
private:
template<class T> void AddSystem(T * system)
{
size_t count = mSystems.size();
auto pair = std::make_pair(system->GetType(), (T*)system);
mSystems.insert(pair);
if (count == mSystems.size())
std::wcout << "System failed to be added" << std::endl;
else
std::wcout << "System added" << std::endl;
}
void Setup(void);
void ShutDown(void);
void SetupGraphicsSystem(void);
static EngineStatus mEngineStatus;
std::map<SystemType, void*> mSystems;
bool mRunning;
};
}
#endif _TEST_ENGINE_H_
Engine source file:
#include "test_engine.h"
using namespace std;
using namespace Core;
EngineStatus Engine::mEngineStatus = EngineStatus::Invalid;
Engine::Engine(void)
{
mEngineStatus = EngineStatus::Constructing;
Setup();
}
Engine::~Engine(void)
{
mEngineStatus = EngineStatus::Destroying;
ShutDown();
}
int Engine::Run(void)
{
mEngineStatus = EngineStatus::Running;
return 0;
}
void Engine::Setup(void)
{
mEngineStatus = EngineStatus::Setup;
SetupGraphicsSystem();
}
void Engine::ShutDown(void)
{
mEngineStatus = EngineStatus::ShutDown;
wcout << endl;
int count = 0;
size_t total = mSystems.size();
for (auto obj : mSystems)
{
safe_delete(obj.second);
wcout << "\rSystem(s) deleted: " << ++count << " of " << total;
}
}
void Engine::SetupGraphicsSystem(void)
{
GraphicsSystem * gs = new GraphicsSystem(mSystems.size(), L"GraphicsSystem01", SystemType::Graphics);
AddSystem(gs);
}
Main source file:
#include "safe_del_rel.h"
#include "strings.h"
#include "test_engine.h"
using namespace std;
using namespace Core;
void _DebugMemLeakDetection(void) {
#if defined(_DEBUG) || defined(DEBUG)
int flag = _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
_CrtSetDbgFlag(flag);
_CrtSetBreakAlloc(0);
#endif
}
int main(int argv, char argc[])
{
_DebugMemLeakDetection();
Engine * eng = new Engine();
eng->Run();
system("pause");
safe_delete(eng);
return 0;
}
Output from last runtime:
'test_engine_console.exe' (Win32): Loaded 'C:\vs_projects\test_engine\x64\Debug\test_engine_console.exe'. Symbols loaded.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Unloaded 'C:\Windows\System32\vcruntime140d.dll'
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
The thread 0x4134 has exited with code 0 (0x0).
The thread 0x46ac has exited with code 0 (0x0).
The thread 0x307c has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{161} normal block at 0x00000293DD5E2680, 48 bytes long.
Data: <G r a p h i c s > 47 00 72 00 61 00 70 00 68 00 69 00 63 00 73 00
{160} normal block at 0x00000293DD5E1820, 16 bytes long.
Data: < R] > A0 52 5D DD 93 02 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The program '[12764] test_engine_console.exe' has exited with code 0 (0x0).
If someone can help plesae do.
Deleting a void * pointer causes undefined behavior, most compilers will issue a warning about this. While the storage for the GraphicsSystem will be freed, its destructor will not be called.
Typically in C++ you would declare std::map<SystemType, Base*> mSystems; where Base is some class all your systems derive from, although mapping to smart pointers to Base is almost always a better idea. If this isn't possible (e.g. GraphicsSystem is an external class) then you could, for example, wrap it in a templated handle that derives from Base.
I was following a video on YouTube that was about hash tables, and while testing some output I realized that my console was skipping quite a few lines.
So my hash table originally was of size 10. When I run the program, everything shows up properly. But when I up the size to 20, my console skips the first 3 indices. I don't know if the problem is with my code, or Visual Studio, but I was hoping someone here would know.
This is a picture of the console output with size 20:
Size 10:
Hash::Hash() {
for (int i = 0; i < tableSize; i++) {
HashTable[i] = new item;
HashTable[i]->name = "empty";
HashTable[i]->drink = "empty";
HashTable[i]->next = NULL;
}
}
int Hash::hashFunction(std::string key) {
int hash = 0;
int index;
for (int i = 0; i < key.length(); i++) {
hash = (hash + (int)key[i]) * 17;
}
index = hash % tableSize;
return index;
}
void Hash::addItem(std::string name, std::string drink) {
int index = hashFunction(name);
if (HashTable[index]->name == "empty") {
HashTable[index]->name = name;
HashTable[index]->drink = drink;
}
else {
item* ptr = HashTable[index];
item* n = new item;
n->name = name;
n->drink = drink;
n->next = NULL;
while (ptr->next != NULL) {
ptr = ptr->next;
}
ptr->next = n;
}
}
int Hash::numItemsIndex(int index){
int count = 0;
if (HashTable[index]->name == "empty")
return count; //0
else {
count++;
item* ptr = HashTable[index];
while (ptr->next != NULL) {
count++;
ptr = ptr->next;
}
}
return count;
}
void Hash::printTable(){
int number;
for (int i = 0; i < tableSize; i++) {
number = numItemsIndex(i);
cout << "-------------------------\n";
cout << "Index = " << i << endl;
cout << HashTable[i]->name << endl;
cout << HashTable[i]->drink << endl;
cout << "# of items = " << number << endl;
cout << "-------------------------\n";
}
}
void Hash::printItemsInIndex(int index){
item* Ptr = HashTable[index];
if (Ptr->name == "empty")
cout << "Index " << index << " is empty. \n";
else {
cout << "Index " << index << " contains the following items: \n";
while (Ptr != NULL) {
cout << "-------------------------\n";
cout << Ptr->name << endl;
cout << Ptr->drink << endl;
cout << "-------------------------\n";
Ptr = Ptr->next;
}
}
}
int main(int argc, char* argv[]) {
Hash Hashy; //create of tablesize 10 and initialize
// all with items -> empty, empty, NUll.
Hashy.addItem("Paul", "Locha");
Hashy.addItem("Kim", "Iced Mocha");
Hashy.addItem("Emma", "Strawberry Smoothie");
Hashy.addItem("Annie", "Hot Chocolate");
Hashy.addItem("Sarah", "Passion Tea");
Hashy.addItem("Pepper", "Caramel Mocha");
Hashy.addItem("Mike", "Chai Tea");
Hashy.addItem("Steve", "Apple Cider");
Hashy.addItem("Bill", "Root Beer");
Hashy.addItem("Marie", "Skinny Latte");
Hashy.addItem("Susan", "Water");
Hashy.addItem("Joe", "Green Tea");
Hashy.printTable();
//Hashy.printItemsInIndex(8);
system("pause");
return 0;
}
There are some things in the output section, but I don't know what they mean:
'LetsHash.exe' (Win32): Loaded 'C:\Users\Rohan Vidyarthi\Desktop\LetsHash\Debug\LetsHash.exe'. Symbols loaded.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\kernel32.dll'
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\WRusr.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wininet.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleacc.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\urlmon.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\secur32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msimg32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
The thread 0xbc8 has exited with code 252968960 (0xf140000).
The thread 0x1700 has exited with code 0 (0x0).
The thread 0x19bc has exited with code 0 (0x0).
The thread 0x1b70 has exited with code 0 (0x0).
The program '[3484] LetsHash.exe' has exited with code 0 (0x0).
Your hash function does not produce a unique number for each string, therefore some of the indices will be duplicate. You can see this if you print out the index for each string:
Paul, 0
Kim, 3
Emma, 6
Annie, 7
Sarah, 1
Pepper, 2
Mike, 2
Steve, 9
Bill, 9
Marie, 0
Susan, 6
Joe, 8
You will need a much larger range for the hash values to avoid hash collisions. 0..9 is too small range and it will almost generate a collision with your current approach.
The error are due to you dont have symbol files for ntdll and all other. What you can do to avoid this error are :- There are multiple options you can have.
Download symbol package provided by microsoft. This will download PDB for all system libraries. Extract it to "c:\symbolcache"
Set symbol path to SRVc:\symbolcachehttp://msdl.microsoft.com/download/symbols. In this case this will download PDB files into "c:\symbolcache" if not present.
Then you have to set "c:\symbolcache" as your symbol file path into whatever crash dump analysis tool you are using.
For the error can you share the code how are you calling the hash.
My problem is in the following code (win8 x64, visual studio):
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define ARMA_USE_BLAS
#define ARMA_USE_LAPACK
#include <armadillo>
using namespace std;
using namespace arma;
int main() {
int b_mean = 20;
int b_max = 4 * b_mean;
double p = 0.04265748215642;
double F_bmax = 1 - pow((1 - p), (b_max + 1));
double alpha = 0.1;
vector<double> THR(EMAXRANGE + 1, 0);
vector <vector <int> > q_finali(EMAXRANGE + 1, vector <int>(4, 0));
const int MAX_E = 8;
const int ORDINE = (int) pow((MAX_E + 1), 2);
printf("EMAX=%d \n", MAX_E);
const int etilde = (int) ceil((double) (MAX_E) / 2);
//costruisco index
vector <vector <int> > index(ORDINE, vector <int>(2, 0));
int riga = 0;
int i, j;
for (i = 0; i <= MAX_E; i++) {
for (j = 0; j <= MAX_E; j++) {
index[riga][0] = i;
index[riga][1] = j;
//printf("i=%d, j=%d, riga=%d \n",i,j,riga);
riga++;
}
}
// costruisco Q
vector <vector <int> > Q((2 * MAX_E) + 1, vector <int>(2, 0));
Q[0][0] = 0; Q[0][1] = 0;
riga = 1;
for (j = 1; j <= MAX_E; j++) {
Q[riga][0] = 0;
Q[riga][1] = j;
riga++;
}
for (i = 1; i <= MAX_E; i++) {
Q[riga][0] = i;
Q[riga][1] = 0;
riga++;
}
int q_LL, q_LH, q_HL, q_HH;
double G_max = 0;
vector <vector <double> > P(ORDINE, vector <double>(ORDINE, 0));
vector <double> g(ORDINE);
int row;
int tmp1;
int tmp2;
double rew;
double temp;
#pragma omp parallel for
for (q_HH = 1; q_HH <= (2 * MAX_E); q_HH++) {
printf("q_HH=%d \n", q_HH);
mat A = mat(ORDINE, ORDINE);
/////// other things //////////
}
}
All is working correctly, until the matrix definition, when an error occurs. This is my output:
'Prova.exe' (Win32): caricamento di 'C:\Users\Davide\Documents\Visual Studio 2012\Projects\Prova\Debug\Prova.exe' completato. Simboli caricati.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\ntdll.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Program Files\AVAST Software\Avast\snxhk.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\kernel32.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\KernelBase.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\msvcp110d.dll' completato. Simboli caricati.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\msvcr110d.dll' completato. Simboli caricati.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\vcomp110d.dll' completato. Simboli caricati.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\user32.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\gdi32.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\imm32.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\msctf.dll' completato. Impossibile trovare o aprire il file PDB.
'Prova.exe' (Win32): caricamento di 'C:\Windows\SysWOW64\msvcrt.dll' completato. Impossibile trovare o aprire il file PDB.
Debug Assertion Failed!
Program: C:\Windows\SYSTEM32\MSVCP110D.dll
File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector
Line: 1140
Expression: vector subscript out of range
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
Second Chance Assertion Failed: File c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector, Line 1140
Prova.exe ha avviato un punto di interruzione.
I think it is something caused by the matrix definition, as if I comment that line all runs smoothly.
Here it is a translation of the error message:
'Prova.exe' (Win32): loading of 'C:\Users\Davide\Documents\Visual Studio 2012\Projects\Prova\Debug\Prova.exe' completed. Symbols loaded.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\ntdll.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Program Files\AVAST Software\Avast\snxhk.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\kernel32.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\KernelBase.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\msvcp110d.dll' completed. Symbols loaded.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\msvcr110d.dll' completed. Symbols loaded.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\vcomp110d.dll' completato. Symbols loaeded.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\user32.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\gdi32.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\imm32.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\msctf.dll' completed. Impossible to find or open the PDB file.
'Prova.exe' (Win32): loading of 'C:\Windows\SysWOW64\msvcrt.dll' completed. Impossible to find or open the PDB file.
Debug Assertion Failed!
Program: C:\Windows\SYSTEM32\MSVCP110D.dll
File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector
Line: 1140
Expression: vector subscript out of range
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
Second Chance Assertion Failed: File c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector, Line 1140
Prova.exe has run an interruption point.
I'm trying to make a command which will close all processes, but it will not work for me.
#include "StdAfx.h"
int _tmain(int argc, _TCHAR* argv[])
{
// Get the list of process identifiers.
DWORD ExitCode;
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
{
return 1;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// exit each process.
for ( i = 0; i < cProcesses; i++ )
{
std::cout<<"end";
if( aProcesses[i] != 0 )
{
GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
ExitProcess(ExitCode);
}
}
}
In addition, I get those errors:
> 'check2.exe': Loaded 'C:\Users\Barak Shriky\Documents\Visual Studio 2010\Projects\check2\Debug\check2.exe', Symbols loaded.
'check2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Symbols loaded (source information stripped).
The program '[3292] check2.exe: Native' has exited with code -858993460 (0xcccccccc).
Can someone please help me with this issue?
1) You are not getting any errors
2) ExitProcess is ending your process. Please read the documentation.
Looks to me like it's working just fine - you just haven't got symbols installed for some system DLL's, which is normal.
Of course, you would get a more meaningful message of why the process exited if you actually set ExitCode to something - say ExitCode = 0xDeadBeef; - and then you would see that it was YOUR process that killed itself.
Doing this seems like a very bad thing to do (assuming it is "successful" in closing the process in the first place), since there are certainly plenty of processes in Windows that when stopped causes the rest of the system to not work very well. Such as the page-in/out process, for example, which is also used to load/unload executables. Being SLIGHTLY more selective in which processes you kill will probably be useful.
see the code below where I used terminate process...
// exit each process.
for ( i = 0; i < cProcesses; i++ )
{
std::cout<<"end";
if( aProcesses[i] != 0)
{
GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
TerminateProcess(aProcesses[i], ExitCode);
}
}
}