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 4017414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:51:28+00:00 2026-05-20T09:51:28+00:00

My code that I have is quite large and complicated so I won’t waste

  • 0

My code that I have is quite large and complicated so I won’t waste your time reading it, but you’re going to have to make certain assumtions about variables in it as a result. I will tell you the values of the variables which I have confirmed in the debugger so you know with certainty. Know that I have omitted a lot of unrelated code in here so what you see isn’t everything but I have included everything that is relevant.

// This is defined in a class:
char**** m_DataKeys;


// This is in a member function of the same class:
m_DataKeys = new char*** [m_iNumOfHeroes];  // m_iNumOfHeroes = 2

while ( pkvHero )
{
  // iHeroNum = 0 and then 1      #define NUM_OF_ABILITIES 4
  m_DataKeys[iHeroNum] = new char** [NUM_OF_ABILITIES];

  for (int ability = 0; ability < NUM_OF_ABILITIES; ability++)
  {
    if (pkvExtraData)  // only is true when iHeroNum == 1 and ability == 0
    {
      // iNumOfExtraData == 2
      m_DataKeys[iHeroNum][ability] = new char* [iNumOfExtraData];

      while ( pkvSubKey )
      {
        // iCurExtraDataNum increments from 0 to 2
        m_DataKeys[iHeroNum][ability][iCurExtraDataNum] = new char [50];

I put a break point on the line

m_DataKeys[iHeroNum] = new char** [NUM_OF_ABILITIES];

Before the line is called and when iHeroNum == 0 the m_DataKeys array looks like:

m_DataKeys | 0x02072a60
  pointer | 0xffeeffee
    Error : expression cannot be evaluated

Which is expected. After the line gets called it looks like:

m_DataKeys | 0x02072a60
  pointer | 0x02496b00
    pointer | 0xffeeffee
      Error : expression cannot be evaluated

Which seems to look correct. However, since I set a breakpoint there, I hit play and had it hit it on the next loop around, where iHeroNum == 1 now and ran the line and m_DataKeys then looked like this:

m_DataKeys | 0x02072a60
  pointer | 0x02496b00
    pointer | 0xffeeffee
      Error : expression cannot be evaluated

Which is the exact same as before! The line didn’t change the array…. At all!

For clarification, m_DataKeys is a 3 dimensional array of character pointers to character arrays of size 50.

I can’t figure out why this is happening, it looks like my code is correct. Is it possible that the garbage collector is screwing me over here? Or maybe the new allocator?

Edit: A Symptom of a Larger Problem

Let me elaborate a little more on the structure of my code, because really, this is just a cheap solution to a bigger problem.

I already have structs as one of you wisely suggested:

struct HeroData
{
  // Lots o data here
  // ...
  // .
  //
  AbilityData* Abilities[NUM_OF_ABILITIES];
}

struct AbilityData
{
  // More data here
  // ...
  // .
  CUtlMap<char*,int> ExtraData [MAX_ABILITY_LEVELS];
}

Now when it got complicated and I had to do this DataKeys arrays of pointers to arrays of pointers crap is only when the need arose to be loading in some data to a dynamic structure, where both the keys, the values, and the numbers of data are completely dynamic. So I thought to use a map of char arrays to ints, but the only problem is that I can’t store the actual char array in my map, I have to use a char *. I tried defining the map as:

CUtlMap<char[50],int> ExtraData [MAX_ABILITY_LEVELS];

But that really didn’t work and it seems sort of strange to me anyway. So, I had to find some place to stick all these ExtraDataKeys and for some reason I thought it cool to do it like this. How can I store char arrays in objects like arrays or maps?

  • 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-05-20T09:51:29+00:00Added an answer on May 20, 2026 at 9:51 am

    Not sure why this didn’t occur to me last night, but I was pretty tired. Heres what I decided to do:

    struct AbilityData
    {
      // Stuff
    
      CUtlMap<char*,int> ExtraData [MAX_ABILITY_LEVELS];
      char **DataKeys;
    }
    

    Thats what my abilityData struct now looks like, and it now works, but now I want to reorganize it to be like:

    struct AbilityData
    {
      // Stuff
    
      CUtlMap<char*,int[MAX_ABILITY_LEVELS]> ExtraData;
      char **DataKeys;
    }
    

    Because it makes more sense that way, but then I run into the same problem that I had before with the char array. It almost seems like to me it might just be best to ditch the whole map idea and make it like:

    struct AbilityData
    {
      // Stuff
    
      int *ExtraData;
      char **DataKeys;
    }
    

    Where ExtraData is now also a dynamically allocated array.

    The only problem with that is that I now have to get my data via a function which will loop through all the DataKeys, find a matching key for my input string, then return the ExtraData associated with it.

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

Sidebar

Related Questions

Hashtables have a syncroot property but generic dictionaries don't. If I have code that
I am querying information from Active Directory . I have code that works, but
An application I have reads in quite large images (jpegs) but only needs to
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying the
I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
Following on from this question I now have code that can attach to a
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
Suppose I have some code that would, in theory, compile against any version of
I currently have some code that will produce a crash dump when my application

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.