Home Help Center

error: bad allocation

arisenarisen Member Senol ArikanOrganization: ZLW/IMAProject: RFID Middleware
hello,
I try to run my Code but it gives me error "bad allocation". Can you please tell me, where i make mistake.

thanks

interface###################
#ifndef SIMPLE_SENDER
#define SIMPLE_SENDER

module Test
{

interface Sender
{
void toPost(string m);
};

};

#endif

server#####################
#include "stdafx.h"
#include "Server.h"

using namespace std;
using namespace AutoMiPro;

int Server::run(int argc, char* argv[])
{

shutdownOnInterrupt();

Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("dataToPost");
dataToPostPtr datatopost = new PostI;
adapter->add(datatopost, communicator()->stringToIdentity("datatopost"));


adapter->activate();

PostI* postObject= new PostI();
this->data = postObject->getDataToServer();

cout << "Server Data: " << this->data << endl;

communicator()->waitForShutdown();

return EXIT_SUCCESS;
}

int main(int argc, char* argv[] )
{
Server app;
return app.main(argc, argv);

}


client###########################

#include "stdafx.h"
#include "Client.h"
#include <Ice/Ice.h>
#include <iostream>
#include <fstream>


using namespace std;
using namespace AutoMiPro;

int Client::run(int argc, char* argv[])
{

dataToPostPrx post = dataToPostPrx::checkedCast(
communicator()->propertyToProxy("dataToPost.Proxy")->ice_twoway());


ifstream xmlDatei("XML_Demo.xml");

while (!xmlDatei.eof()){

xmlDatei >> this->data;
this->dataToSend.append(data);
}
this->result = post->publishDataMessageTwoWay(this->dataToSend);


return EXIT_SUCCESS;
}
int main(int argc, char* argv[] )
{
Client app;
return app.main(argc, argv);

}

Comments

  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    You don't say where the error happens (client or server) or at what line. Also, you don't show the complete server implementation and, from looking at the code I don't think that is the exact code that causes your problem.

    I'd suggest that you start with one of the demos that come with Ice (the minimal demo is a good starting point) and modify that. Chances are that you will discover where you went wrong. I'd also recommend that you have read of the introductory sections of the manual and the C++ mapping chapters.

    If you still have a problem, we need a complete, self-contained, compilable example that demonstrates the issue.

    Cheers,

    Michi.
  • arisenarisen Member Senol ArikanOrganization: ZLW/IMAProject: RFID Middleware
    bad allocation

    hi,

    I post you my server and client code. if i compile, i don't receive error; but if i want to run server or client in the console, than i get "bad allocation".

    thank you



    server##############
    #include "stdafx.h"
    #include <Ice/Ice.h>
    #include "Sender.h"

    using namespace std;
    using namespace Mod;

    class SenderI : public Sender{
    public:
    virtual void toSend(const string& s, const Ice::Current&);
    };

    void SenderI::toSend(const string& s, const Ice::Current&)
    {
    cout << s << endl;

    };


    class Server:public Ice::Application
    {
    public:
    virtual int run(int, char*[]);
    };

    int Server::run(int, char *[])
    {
    shutdownOnInterrupt();
    Ice::ObjectAdapterPtr adapter =
    communicator()->createObjectAdapterWithEndpoints("SimpleSenderAdapter", "default -p 10000");
    Ice::ObjectPtr object = new SenderI;
    adapter->add(object, communicator()->stringToIdentity("SimpleSender"));
    adapter->activate();
    communicator()->waitForShutdown();
    return 0;
    }

    int main(int argc, char* argv[])
    {
    Server server;
    return server.main(argc, argv);
    }


    client##########################################
    // Ice-Client.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
    //

    #include "stdafx.h"
    #include <Ice/Ice.h>
    #include "Sender.h"

    using namespace std;
    using namespace Mod;

    class Client : public Ice::Application
    {
    public:
    virtual int run (int, char*[]);
    };

    int Client::run(int, char *[])
    {

    Ice::ObjectPrx base = communicator()->stringToProxy("SimpleSender:default -p 10000");

    SenderPrx sender = SenderPrx::checkedCast(base);
    if(!sender)
    throw "Invalid proxy";
    sender->toSend("Hello!!!");
    return 0;
    }

    int main(int argc, char* argv[])
    {
    Client client;
    return client.main(argc, argv);
    }

    slice####################################

    module Mod{
    interface Sender{
    void toSend(string data);
    };
    };
  • dwaynedwayne St. John's, NewfoundlandMember Dwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications Engine
    What version of Ice are you using? What OS/compiler are you using?
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    What operating system and compiler? If this is under windows, are you mixing up the runtime library? For example, compiling with /MDd and linking with the release runtime, or vice versa?
  • arisenarisen Member Senol ArikanOrganization: ZLW/IMAProject: RFID Middleware
    bad allocation

    hi,
    i am using Windows XP and Visula Studio 2005, i have Ice-3.3.0.

    thanks
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Most likely the reason is as I said. See http://www.zeroc.com/faq/windowsLibraryMixup.html for some more information.
Sign In or Register to comment.