Jump to content

Whisper Memory Fix


Mali

Recommended Posts

A slightly more optimized code for the second solution.

CWhisper* CPythonChat::CreateWhisper(const char* c_szName)
{
	auto itor = m_WhisperMap.find(c_szName);

	CWhisper* pWhisper;

	if (itor == m_WhisperMap.end())
	{
		pWhisper = CWhisper::New();
		m_WhisperMap.emplace(c_szName, pWhisper);
	}
	else
	{
		pWhisper = itor->second;
	}

	return pWhisper;
}

I'm sorry to bother you.

  • Facepalm 1
  • Love 1
Link to comment
Share on other sites

  • Honorable Member
1 hour ago, Chookez said:

A slightly more optimized code for the second solution.

CWhisper* CPythonChat::CreateWhisper(const char* c_szName)
{
	auto itor = m_WhisperMap.find(c_szName);

	CWhisper* pWhisper;

	if (itor == m_WhisperMap.end())
	{
		pWhisper = CWhisper::New();
		m_WhisperMap.emplace(c_szName, pWhisper);
	}
	else
	{
		pWhisper = itor->second;
	}

	return pWhisper;
}

I'm sorry to bother you.

So your optimized code is auto and emplace

Can you explain what you optimized exactly?

Edit: If your optimize is using modern c++ functions like emplace, I don't use this on purpose.

Spoiler

.png

 

Edited by Mali
  • Not Good 1
  • Smile Tear 1
  • Lmao 1

 

Link to comment
Share on other sites

  • Honorable Member

Don't argue with experienced ones, they will win.

Anyway, anyone who is using modern c++ on their source has the brain to convert anything they want to adapt to their code without even mention it.
smart-black-guy.jpg

Edited by Metin2 Dev International
Core X - External 2 Internal
  • Metin2 Dev 1
  • Good 3
  • Love 1
Link to comment
Share on other sites

  • Honorable Member
6 minutes ago, xP3NG3Rx said:

Don't argue with experienced ones, they will win.

Anyway, anyone who is using modern c++ on their source has the brain to convert anything they want to adapt to their code without even mention it.
smart-black-guy.jpg

I used to use modern C++ on my systems back then, but then I saw some people complaining about it (compiler problems, etc.).

Later, I started not even using auto in order to alleviate these complaints and to maintain code integrity with Metin2's old source codes.

 

Like you said "anyone who is using modern c++ on their source has the brain to convert anything they want to adapt to their code without even mention it."🤣👍

 

Link to comment
Share on other sites

  • Honorable Member
10 hours ago, blaxis said:

thank you for sharing.

There are many memory problems in Metin2 that are waiting to be fixed and cause unnecessary CPU increase. Do you have a post about these?

They are not easy to find. Think it's been 10 years since the source codes were leaked, we even just found this😆

I share what I found👍

  • Good 2
  • Love 4

 

Link to comment
Share on other sites

On 10/16/2023 at 6:02 PM, Chookez said:

A slightly more optimized code for the second solution.

CWhisper* CPythonChat::CreateWhisper(const char* c_szName)
{
	auto itor = m_WhisperMap.find(c_szName);

	CWhisper* pWhisper;

	if (itor == m_WhisperMap.end())
	{
		pWhisper = CWhisper::New();
		m_WhisperMap.emplace(c_szName, pWhisper);
	}
	else
	{
		pWhisper = itor->second;
	}

	return pWhisper;
}

I'm sorry to bother you.

 

I would consider this to be a "optimization":

 

CWhisper* CPythonChat::CreateWhisper(const char* c_szName)
{
	auto [itor, inserted] = m_WhisperMap.try_emplace(c_szName, nullptr);
	if (inserted)
	{
		itor->second = CWhisper::New();
	}
	return itor->second;
}


Best regards

  • Metin2 Dev 1
  • Sad 1
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.