Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:46:50+00:00 2026-06-07T18:46:50+00:00

Possible Duplicate: Cost of using std::map with std::string keys vs int keys? if I

  • 0

Possible Duplicate:
Cost of using std::map with std::string keys vs int keys?

if I have the two pieces of code:

1#:

map<unsigned int, unsigned short> ConnectedIPs;

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid)
{
    PlayerLoopList.push_back(playerid);
    char szIP[32];
    GetPlayerIp(playerid,szIP);
    unsigned short explodeIP[4];
    sscanf(szIP, " %d[^.].%d[^.].%d[^.].%d", &explodeIP[0], &explodeIP[1], &explodeIP[2], &explodeIP[3]);
    g_PlayerIP[playerid] = (explodeIP[0] + (explodeIP[1] << 8) + (explodeIP[2] << 16) + (explodeIP[3] << 24));
    ConnectedIPs[g_PlayerIP[playerid]] += 1;
    if(ConnectedIPs[g_PlayerIP[playerid]] >= g_max_ip)
    {
        Report(playerid,CHECK_IPFLOOD);
    }
    return true;
}

2#:

map<char*, unsigned short> ConnectedIPs;//edited from char to char*

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid)
{
    PlayerLoopList.push_back(playerid);
    char szIP[32];
    GetPlayerIp(playerid,szIP);
    ConnectedIPs[szIP] += 1;
    if(ConnectedIPs[szIP] >= g_max_ip)
    {
        Report(playerid,CHECK_IPFLOOD);
    }
    return true;
}

would 2# be faster?
This code is for counting the amount of connected players fron one ip. I think I am doing it right, or I’m not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:46:52+00:00Added an answer on June 7, 2026 at 6:46 pm

    I’m assuming you meant map<string, unsigned short> for the second case, otherwise it won’t even compile.

    Both trigger an O(log n) lookup in the map based on comparisons of keys. Comparing 32 bit integers is generally faster than comparing strings, so the first case should be faster.

    I wouldn’t worry about it though, unless there’s profiling data showing this to have a significant impact on performance. If you do that only when the player connects, and the session tends to last “long enough”, chances are this would be an insignificant optimization – and even then, switching to unordered_map will probably be more significant than changing the type of the key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: Convert a long hex string in to int array with sscanf I
Possible Duplicate: In Java, for a string x, what is the runtime cost of
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: What is the performance cost of having a virtual method in a
Possible Duplicate: How much does it cost to develop an iphone application? Hope somebody
Possible Duplicate: What is a reasonable code coverage % for unit tests (and why)?
Possible Duplicate: What is the “cost” of .NET reflection? I'm a little surprised this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.