Jump to content

Reduce server memory usage


Recommended Posts

  • 3 weeks later...
  • Honorable Member
6 hours ago, Amun said:

By using what Marty posted here

I've recently moved it outside PointsInstant (just for a better design style)

		CHARACTER_POINT_INSTANT	m_pointsInstant;
		std::unique_ptr<PlayerSlotT> m_PlayerSlots;

and included QuickSlot as well without any issues. (just check in char_quickslot.cpp if the unique_ptr is nullptr like always)

struct PlayerSlotT {
	std::array<LPITEM,INVENTORY_AND_EQUIP_SLOT_MAX> pItems;
	std::array<BYTE,INVENTORY_AND_EQUIP_SLOT_MAX> bItemGrid;
	std::array<LPITEM,DRAGON_SOUL_INVENTORY_MAX_NUM> pDSItems;
	std::array<WORD,DRAGON_SOUL_INVENTORY_MAX_NUM> wDSItemGrid;
	std::array<LPITEM,CUBE_MAX_NUM> pCubeItems;
#ifdef ENABLE_ACCE_COSTUME_SYSTEM
	std::array<TItemPosEx,ACCE_WINDOW_MAX_MATERIALS> pAcceMaterials;
#endif
	std::array<TQuickslot,QUICKSLOT_MAX_NUM> pQuickslot;
};

By using std::array instead of c-arrays, you'll get these differences:

  • You may need to use XXX.data() to get the raw ptr in few occasions.
  • memset is now useless garbage, because XXX = {} does that job for you
  • You get assertions if the array subindex goes out of bound
  • You can use all the generic features std:: containers support

What doesn't change is that std::array is still considered a trivial type for the template trails, and can also be used for client<>server packets.

Edited by martysama0134
  • Metin2 Dev 3
  • Scream 1
  • Good 2
  • Love 5
Link to comment
Share on other sites

  • 3 months later...

The biggest fundamental flaw is that players and monsters use the same class and packet communication. This error causes unnecessary memory usage and unnecessarily long processing times. Action on this issue is only a minor improvement. More improvements should be made for large projects. All source code should be modular and independent of each other, with small packet communication and short processing times.

  • Good 1
Link to comment
Share on other sites

  • 2 weeks later...
On 9/8/2022 at 5:36 PM, Amun said:

Pretty cool idea.

By using what Marty posted here

  Reveal hidden contents

 

The core reduced memory usage from 471 MB to 221, with a peak of 243 MB when booting(loading).

.png

 

i did everything the same but there is such a bug

https://metin2.download/picture/9Zj97oEe003IAgxykVqjZ4kYmlK86Z02/.png

and i used unique_ptr instead of make_unique in part SetPlayerProto.

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Honorable Member
1 hour ago, bossy_max said:

@ martysama0134what can I use instead of make_unique ?

This is its definition:

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
Edited by martysama0134
Link to comment
Share on other sites

8 hours ago, martysama0134 said:

This is its definition:

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

i will use it this thank you

m_pointsInstant.playerSlots = std::unique_ptr<character_point_instant::PlayerSlotT>(new character_point_instant::PlayerSlotT());

 

Link to comment
Share on other sites

  • 4 months later...
On 11/5/2021 at 1:20 PM, martysama0134 said:

There are far better solutions than using std::map or std::unordered_map (which still takes a lot of ram for no reason for each mob):

(I included the most important parts)

You also forgot the CubeItems, and we could probably fit the quickslot too.

  Reveal hidden contents

u6xpuP5.png

8l52tEd.png

QuAep2f.png

DyiEUfe.png

ls2VRPX.png

from running 1 channel - x3 cores on 2GB RAM and an additional 800MB swap -> running 4 channels -  x12 cores on 2GB RAM and an additional 1.1GB swap 

this is huge

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.