C++ API v1.7.2 and SpaceWar example released

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

User avatar
Bax
Site Admin
Posts: 4322
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

C++ API v1.7.2 and SpaceWar example released

Postby Bax » 19 Apr 2017, 14:46

We just released version 1.7.2 of the C++ API for SmartFoxServer 2X.
This release contains a number of fixes to issues reported by developers.
Check the release notes and download the new API on this page: http://www.smartfoxserver.com/download/sfs2x#p=client

We also just released a new version of our C++ examples package, available on this page: http://www.smartfoxserver.com/download/sfs2x#p=examples
The package now contains the Cocos2D-x porting of our SpaceWar demo game, for which a full tutorial is also available in our official documentation.
The game has been developed by Dang Hoang Tuan Anh after our "call to arms" (see this post: viewtopic.php?f=34&t=15891). It comes with the source code and full instructions to setup the development environment to deploy the game to multiple platforms (iOS, Android, Windows).
Paolo Bax
The SmartFoxServer Team
doananhtai
Posts: 3
Joined: 06 Jun 2017, 01:59

Re: C++ API v1.7.2 and SpaceWar example released

Postby doananhtai » 06 Jun 2017, 02:06

In this SpaceWar example
I found the ExtensionRequest cause the memory increase until "terminated due to memory issue"

I think the problem is "new SFSObject()" and "(new ExtensionRequest(..)" with down delete..,
but I cannot find the correct way to release them... the .reset() not effected.
User avatar
Lapo
Site Admin
Posts: 19555
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 06 Jun 2017, 07:03

Hi,
if I remember correctly the SFSObject passed to the ExtensionRequest(...) constructor is a boost:shared_ptr (a smart pointer). It shouldn't cause that problem. What makes you think the memory issue is caused by that?
Lapo
--
gotoAndPlay()
...addicted to flash games
doananhtai
Posts: 3
Joined: 06 Jun 2017, 01:59

Re: C++ API v1.7.2 and SpaceWar example released

Postby doananhtai » 06 Jun 2017, 08:57

//Call this 20 times a second
boost::shared_ptr<ISFSObject> params = boost::shared_ptr<ISFSObject>(new SFSObject());
boost::shared_ptr<ExtensionRequest> request(new ExtensionRequest(REQ_CODE, params, room));
ptrSmartFox->Send(request);

//the memory increase until "terminated due to memory issue"
I don't know how to fix it.
doananhtai
Posts: 3
Joined: 06 Jun 2017, 01:59

Re: C++ API v1.7.2 and SpaceWar example released

Postby doananhtai » 06 Jun 2017, 09:22

I had solved this problem

Not use boost in example (SpaceWar/client/extenal/boost)
I download boost1.64.0 instead

In SmartFoxClientAPi library project
HeaderSearch and LibrarySearch do not use [api_folder]/Core/BoostAsio/Unix... use the path of boost1.64.0

and..with the old boost the ~MyStruct() never touch..but the new (1.64.0) does.
struct MyStruct {
MyStruct() {
cocos2d::log("new");
}

~MyStruct() {
cocos2d::log("delete");
}
};
auto x = boost::shared_ptr<MyStruct>(new MyStruct());

Thanks for All.
User avatar
Lapo
Site Admin
Posts: 19555
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 06 Jun 2017, 10:07

Thanks for your feedback.
However I am not sure why changing the version of Boost would make a difference.

I have tested with the current API using this code:

Code: Select all

void SimpleConnector::fastExtensionCall()
{
    int sleepMicros = 10 * 1000; // 100 pps
   
    for (int i = 0; i < 30000; i++)
    {
        auto params = boost::shared_ptr<ISFSObject>(new SFSObject());
        auto extReq = boost::shared_ptr<ExtensionRequest>(new ExtensionRequest("echo", params));
   
        sfs->Send(extReq);
       
        if (i % 1000 == 0)
            cout << "Ext req sent :: " << i << endl;
       
        usleep(sleepMicros);
    }
    cout << "---- DONE ----" << endl;
}


This fires 100 packets per second to the server for a total of 30K packets. I see the memory growing because all allocations are done inside the function. In other words all pointers are allocated on the stack and won't go away until the function returns. The memory grows up to 12-13 MBytes and when the function is done it drops back down to 2MBytes, which seems to indicate there are no memory leaks.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
phongka
Posts: 2
Joined: 13 Jun 2017, 10:37

Re: C++ API v1.7.2 and SpaceWar example released

Postby phongka » 13 Jun 2017, 10:44

Bax wrote:We just released version 1.7.2 of the C++ API for SmartFoxServer 2X.
This release contains a number of fixes to issues reported by developers.
Check the release notes and download the new API on this page: http://www.smartfoxserver.com/download/sfs2x#p=client

We also just released a new version of our C++ examples package, available on this page: http://www.smartfoxserver.com/download/sfs2x#p=examples
The package now contains the Cocos2D-x porting of our SpaceWar demo game, for which a full tutorial is also available in our official documentation.
The game has been developed by Dang Hoang Tuan Anh after our "call to arms" (see this post: viewtopic.php?f=34&t=15891). It comes with the source code and full instructions to setup the development environment to deploy the game to multiple platforms (iOS, Android, Windows).


Hi Bax,

I'm trying to build SpaceWar project on iOS platform, I'm using xcode. But I don't see SmartFoxClientApi project for Xcode (I use the new API: SFS2X_API_Cpp_v1.7.3). Please help to check this case. Thanks.
User avatar
Lapo
Site Admin
Posts: 19555
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 13 Jun 2017, 14:12

Hi,
the API are not provided with the example. Make sure to follow the build instructions here:
http://docs2x.smartfoxserver.com/ExamplesCpp/spacewar

If you have already built the API for iOS you will need to add them to the project together with the relative header files and dependencies.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
phongka
Posts: 2
Joined: 13 Jun 2017, 10:37

Re: C++ API v1.7.2 and SpaceWar example released

Postby phongka » 14 Jun 2017, 02:31

Lapo wrote:Hi,
the API are not provided with the example. Make sure to follow the build instructions here:
http://docs2x.smartfoxserver.com/ExamplesCpp/spacewar

If you have already built the API for iOS you will need to add them to the project together with the relative header files and dependencies.

cheers


Hi,

But I can not download the API in the above site (detail in attached file).
Attachments
Screen Shot 2017-06-14 at 9.34.58 AM.png
(242.68 KiB) Not downloaded yet
User avatar
Bax
Site Admin
Posts: 4322
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: C++ API v1.7.2 and SpaceWar example released

Postby Bax » 14 Jun 2017, 06:55

Sorry, the link was missing, now it is fixed.
Anyway you can get the C++ API here: http://www.smartfoxserver.com/download/sfs2x#p=client
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 15 guests