Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket  (Read 4588 times)

0 Members and 1 Guest are viewing this topic.

spacechase0

  • Newbie
  • *
  • Posts: 39
    • AOL Instant Messenger - thespacechase0
    • View Profile
    • http://spacechase0.com/
sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« on: April 14, 2010, 05:34:47 pm »
I'm finally trying the networking package again, but I'm having another problem, which is probably another silly mistake. :(

I'm using SFML 1.5 (dynamically linked) (going to upgrade soon) on Windows XP with Code::Blocks.

When I open task manager and go under processes, the far right column is Mem Usage, and processes usually have something like 4,484 K. This number goes up by around 10,000 (for the application I'm trying to make) every half-a-second-ish. I've been playing around with commenting stuff, and I found the problem (I think).

I make a pointer to a socket, and it points to one made with new. At first I thought it happened because I didn't delete it, but when all I had was new and delete, it worked fine.

Earlier, it was only going up when I used SetBlocking to false, but now it does it if I use SetBlocking at all...

Don't bother asking for a minimal example, I already made one! :D

Code: [Select]

#include <SFML/Network.hpp>

using namespace sf;

int main()
{
    bool isTesting = true;
    while ( isTesting )
    {
        sf::SocketTCP *testSocket = new sf::SocketTCP;
        testSocket->SetBlocking( true );
        delete testSocket;
    }
    return 0;
}


For once, I would be happy if it was a silly mistake. :P



Unrelated note: I just recently noticed that the tutorial for setting SFML up said that if I use it dynamically linked I have to define SFML_DYNAMIC in the project settings... I've never done that before! :lol: When I add it in, it works just the same.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« Reply #1 on: April 14, 2010, 05:50:26 pm »
Strange, SetBlocking just does a system call.

Quote
Unrelated note: I just recently noticed that the tutorial for setting SFML up said that if I use it dynamically linked I have to define SFML_DYNAMIC in the project settings... I've never done that before! Laughing When I add it in, it works just the same.

Yep, the linker seems to care only about variables, not functions. If you use the graphics module you'll get some errors.
Laurent Gomila - SFML developer

spacechase0

  • Newbie
  • *
  • Posts: 39
    • AOL Instant Messenger - thespacechase0
    • View Profile
    • http://spacechase0.com/
sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« Reply #2 on: April 14, 2010, 07:01:50 pm »
I just tried updating to 1.6, but it didn't work too well. :P

It still goes up, and when I try to run the executable without going through Code::Blocks (like double clicking the EXE) it says it can't find libgcc_s_dw2-1.dll (like last time I tried to upgrade) (although this time I did try to upgrade the compiler). :roll:

I'm not sure if this helps, but the socket isn't valid before using SetBlocking and afterwards it is.

Quote from: "Laurent"
Quote
Unrelated note: I just recently noticed that the tutorial for setting SFML up said that if I use it dynamically linked I have to define SFML_DYNAMIC in the project settings... I've never done that before! Laughing When I add it in, it works just the same.

Yep, the linker seems to care only about variables, not functions. If you use the graphics module you'll get some errors.


I've never done it when using graphics either...

I'll just keep testing different things.

EDIT: It goes up at a much slower rate (around 100) when I use Listen first:

Code: [Select]

#include <SFML/Network.hpp>
#include <iostream>

using namespace std;
using namespace sf;

int main()
{
    bool isTesting = true;
    bool triedOnce = false;
    while ( isTesting )
    {
        sf::SocketTCP *testSocket = new sf::SocketTCP;
        if ( !triedOnce )
        {
            if ( testSocket->IsValid() )
            {
                cout << "Test 1: Socket is valid." << std::endl;
            }
            else
            {
                cout << "Test 1: Socket isn't valid." << std::endl;
            }
        }
        testSocket->Listen( 23132 );
        if ( !triedOnce )
        {
            if ( testSocket->IsValid() )
            {
                cout << "Test 2: Socket is valid." << std::endl;
            }
            else
            {
                cout << "Test 2: Socket isn't valid." << std::endl;
            }
        }
        testSocket->SetBlocking( true );
        if ( !triedOnce )
        {
            if ( testSocket->IsValid() )
            {
                cout << "Test 3: Socket is valid." << std::endl;
            }
            else
            {
                cout << "Test 3: Socket isn't valid." << std::endl;
            }
        }
        delete testSocket;
        triedOnce = true;
    }
    return 0;
}


It's not valid on test 1 but afterwards it is.

EDIT 2: Changing the order of SetBlocking and Listen doesn't do anything, but if I comment out Listen it goes up fast again.

EDIT 3: SocketUDP does the same thing, except the socket is valid from the start.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« Reply #3 on: April 14, 2010, 07:33:15 pm »
Do you use the debug libraries in debug mode?

Quote
It still goes up, and when I try to run the executable without going through Code::Blocks (like double clicking the EXE) it says it can't find libgcc_s_dw2-1.dll (like last time I tried to upgrade) (although this time I did try to upgrade the compiler).

Add -static-libgcc to the linker options.
Laurent Gomila - SFML developer

spacechase0

  • Newbie
  • *
  • Posts: 39
    • AOL Instant Messenger - thespacechase0
    • View Profile
    • http://spacechase0.com/
sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« Reply #4 on: April 14, 2010, 07:57:05 pm »
Quote from: "Laurent"
Do you use the debug libraries in debug mode?

Yes.

Quote from: "Laurent"
Quote
It still goes up, and when I try to run the executable without going through Code::Blocks (like double clicking the EXE) it says it can't find libgcc_s_dw2-1.dll (like last time I tried to upgrade) (although this time I did try to upgrade the compiler).

Add -static-libgcc to the linker options.

Thanks! :D

spacechase0

  • Newbie
  • *
  • Posts: 39
    • AOL Instant Messenger - thespacechase0
    • View Profile
    • http://spacechase0.com/
sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« Reply #5 on: April 17, 2010, 03:11:41 pm »
I tried making it not a pointer, but that didn't fix it. :(

 

anything