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

Author Topic: Making sense of rudimentary gpu memory test  (Read 2004 times)

0 Members and 1 Guest are viewing this topic.

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Making sense of rudimentary gpu memory test
« on: December 17, 2017, 04:18:29 pm »
Hey folks

I have been doing some very basic gpu memory usage tests with sfml.

I'm having trouble making sense of some things:

I run my test program with no textures loaded. The gpu uses 333 mb of memory.

I dynamically create a drawable class with a 4k texture. The gpu now uses 397 mbs.

I destroy the class. Still 397.

I create another one (4k tex vertexarray class), the gpu now uses 454.

After this point, no matter how many times I create and destroy the drawables (doesn't matter how many different textures I use) the gpu memory is always at 454.

Is this behaviour normal? Can I not get that memory back?

snippets from the test code:


Show* ptrShow = nullptr; // Show class is sf::Drawable with a VertexArray

if (event.key.code == sf::Keyboard::C) // C is for construct
{
        Show* s = new Show{ 1, "red.png" }; // Test 4k texture (one of multiple)
        ptrShow = s;
}

if (event.key.code == sf::Keyboard::D) // D is for destruct
{
        ptrShow->~Show();
        ptrShow = nullptr;
}

if (ptrShow) { window.draw(*ptrShow); }

 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Making sense of rudimentary gpu memory test
« Reply #1 on: December 17, 2017, 08:00:07 pm »
First, you should call delete and not the destructor.

How do you check the GPU memory usage?
Laurent Gomila - SFML developer

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: Making sense of rudimentary gpu memory test
« Reply #2 on: December 17, 2017, 08:55:15 pm »
First, you should call delete and not the destructor.

How do you check the GPU memory usage?

A program called GPU-Z.2.5.0.

So the destructor does not free the memory and this is actually a leak I'm getting? I didn't think that was the case  because the memory usage never went higher than 454. Leak would have kept increasing it?

I realize that this is not an sfml question, but how can I call delete when the key codes are different blocks? I tried putting "delete this" in the destructor but that puts the destructor in an endless loop and crashes the program for reasons I'm trying to figure out.
« Last Edit: December 17, 2017, 09:04:07 pm by NGM88 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Making sense of rudimentary gpu memory test
« Reply #3 on: December 17, 2017, 10:16:55 pm »
Quote
So the destructor does not free the memory and this is actually a leak I'm getting?
You're not releasing the memory taken by the Show instance itself, but since you call the destructor, all its member data will correctly be freed. So this has nothing to do with the GPU, it's just a few bytes (depending on the content of the Show class) leaking in main memory.

Quote
I realize that this is not an sfml question, but how can I call delete when the key codes are different blocks?
I don't understand your problem. What's different between calling the destructor and calling delete?

if (event.key.code == sf::Keyboard::C) // C is for construct
{
        ptrShow = new Show{ 1, "red.png" }; // Test 4k texture (one of multiple)
}

if (event.key.code == sf::Keyboard::D) // D is for destruct
{
        delete ptrShow;
        ptrShow = nullptr;
}

You should also consider using smart pointers (in this case, std::unique_ptr). Again, in this case it is probably not relevant, but it is good practice to avoid manual memory management.
Laurent Gomila - SFML developer

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: Making sense of rudimentary gpu memory test
« Reply #4 on: December 18, 2017, 08:18:17 am »
That clears things. Thanks again, Laurent.