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

  • SEARCH
  • Home
  • 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 5943397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:23:22+00:00 2026-05-22T16:23:22+00:00

I am having an array(m_cPendingEventList) and a dictionary(m_cAppIdMap).when i store the values and keys

  • 0

I am having an array(m_cPendingEventList) and a dictionary(m_cAppIdMap).when i store the values and keys onto the map its unordered and so i’m setting up a mutable array to hold the values in order.I am inserting only one element into the array(m_cPendingEventList). and the element that is stored is a pointer to the structure.

When i’m just printing the dictionary i’m getting the same value for the different keys.However i’m changing the values of one field and storing that structure object onto the map.When i print to see the contents of the map.All the values its showing me for the different keys are the same.Is it the address of the structure pointer.I am new to Objective C and programming.

The problem i’m facing with this code is that i could not able to delete the value stored on the NSMutable array(m_cAppIdMap).

I have given a key for which the value has to be deleted on the array.
I will search the value for the particular key in the map and will pass that value as an argument to the function findAndRemove to delete the value inthat array.Here I could not able to delete the element in the array.

-(BOOL)createTimer
{
    stRs232Timer*   pEvent = malloc(sizeof(stRs232Timer));

    pEvent->bPersistent = YES;                              // setup timer structure
    pEvent->wAppTimerId = 95;
    pEvent->uPeriod     = 50;
    pEvent->bStopped    = NO;


    NSLog(@"bPersistent:%d",pEvent->bPersistent);
    NSLog(@"wAppTimerId:%d",pEvent->wAppTimerId);
    NSLog(@"uPeriod:%d",pEvent->uPeriod);
    NSLog(@"bStopped:%d",pEvent->bStopped);

    theLock = [[NSLock alloc]init];

    NSData* myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];

    wTimerId = 99;
    pEvent->uPeriod = 51;
    myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 96;
    pEvent->uPeriod = 52;
    myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 97;
    pEvent->uPeriod = 53;
    myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 98;
    pEvent->uPeriod = 54;
    myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 95;
    pEvent->uPeriod = 55;
    myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];

    NSLog(@"The dictionary count now is:%d",[m_cAppIdMap count]);
    NSLog(@"The dictionary values now is:");
    NSLog(@"%@",m_cAppIdMap);


    [m_cPendingEventList addObject:myData];
    NSLog(@"EventList:%@",m_cPendingEventList);

    [self KillTimer:95];

    int k = [m_cAppIdMap count];
    NSLog(@"The count of dict :%d",k);
    NSLog(@"My dictionary is:%@",m_cAppIdMap);
    return YES;
}
-(BOOL)KillTimer:(unsigned short)wTimerIds
{
    stRs232Timer* pEvent = malloc(sizeof(stRs232Timer));
    BOOL bReturn=NO;
    theLock = [[NSLock alloc]init];

    if ([theLock tryLock]) {

        NSLog(@"Locked");
            if ([NSNumber numberWithUnsignedShort:wTimerIds]) {
        [m_cAppIdMap removeObjectForKey:[NSNumber numberWithUnsignedShort:wTimerIds]];
        [self findAndRemoveEvent:pEvent];
             }
             NSLog(@"The Dict is:%@",m_cAppIdMap);
            //  NSLog(@"Removed the key");
             free(pEvent);
        /*  }
            else {
                NSLog(@"No key with this Id");
            }
            i++;
            bReturn = YES;
        }*/
        NSLog(@"Unlocked!!");
        NSLog(@"Into KillAll!!!");
        [theLock unlock];
        [self KillAll];
    }   

    return bReturn;
}
-(void)KillAll
{
    //unsigned short wKey;
    stRs232Timer* pEvent;

    theLock = [[NSLock alloc]init];

    /*if ([theLock tryLock]) {

        [m_cPendingEventList removeAllObjects];

        NSEnumerator* enumerator = [m_cAppIdMap keyEnumerator];
        id key;

        while((key = [enumerator nextObject]))
        {
            [m_cAppIdMap objectForKey:[NSNumber numberWithUnsignedShort:wTimerId]];
            free(pEvent);
        }
        [m_cAppIdMap removeAllObjects];
        [theLock unlock];
    }*/
    if([theLock tryLock]){
     [m_cPendingEventList removeAllObjects];
     [m_cAppIdMap removeAllObjects];
    }
    [theLock unlock];
    NSLog(@"The dict now contains:%@",m_cAppIdMap);
}
-(BOOL)findAndRemoveEvent:(const stRs232Timer*)pEvent
{
    int index;
    index = [m_cPendingEventList count];
    for(int i=0;i<index;i++)
    {
        stRs232Timer* stTimer = (stRs232Timer*)[m_cPendingEventList objectAtIndex:i];
        if(stTimer == pEvent)
        {
            NSLog(@"Found the event to remove!!");
            [m_cPendingEventList removeObjectAtIndex:i];
            NSLog(@"Event Removed!!");
        }
        else {
            NSLog(@"No such event!!");
        }

    }
    NSLog(@"The array is:%@",m_cPendingEventList);
    return YES;
}

output:

2011-05-25 14:01:19.812 NSArray[2233:a0f] bPersistent:1
2011-05-25 14:01:19.833 NSArray[2233:a0f] wAppTimerId:95
2011-05-25 14:01:19.836 NSArray[2233:a0f] uPeriod:50
2011-05-25 14:01:19.837 NSArray[2233:a0f] bStopped:0
2011-05-25 14:01:19.838 NSArray[2233:a0f] The dictionary count now is:5
2011-05-25 14:01:19.838 NSArray[2233:a0f] The dictionary values now is:
2011-05-25 14:01:19.839 NSArray[2233:a0f] {
    98 = <b0ca1000 01000000>;
    97 = <b0ca1000 01000000>;
    96 = <b0ca1000 01000000>;
    99 = <b0ca1000 01000000>;
    95 = <b0ca1000 01000000>;
}
2011-05-25 14:01:19.840 NSArray[2233:a0f] EventList:(
    <b0ca1000 01000000>
)
2011-05-25 14:01:19.845 NSArray[2233:a0f] Locked
2011-05-25 14:01:19.846 NSArray[2233:a0f] No such event!!
2011-05-25 14:01:19.846 NSArray[2233:a0f] The array is:(
    <b0ca1000 01000000>
)
2011-05-25 14:01:19.847 NSArray[2233:a0f] The Dict is:{
    98 = <b0ca1000 01000000>;
    97 = <b0ca1000 01000000>;
    96 = <b0ca1000 01000000>;
    99 = <b0ca1000 01000000>;
}
2011-05-25 14:01:19.848 NSArray[2233:a0f] Unlocked!!
2011-05-25 14:01:19.848 NSArray[2233:a0f] Into KillAll!!!
2011-05-25 14:01:19.849 NSArray[2233:a0f] The dict now contains:{
}
2011-05-25 14:01:19.849 NSArray[2233:a0f] The count of dict :0
2011-05-25 14:01:19.850 NSArray[2233:a0f] My dictionary is:{
}
  • 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-22T16:23:23+00:00Added an answer on May 22, 2026 at 4:23 pm

    pEvent is already a pointer. Why are you sending a pointer to it. You will have to create the NSData object like this –

    myData = [NSData dataWithBytes:(void*)pEvent length:sizeof(pEvent)];
    

    This should work.

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

Sidebar

Related Questions

I'm having a bit of difficulty using the values in a PHP array for
I'm trying to query a MySQL database using an array but I'm having trouble!
I'm really having trouble with Allocatable array. I have to copy all information from
I'm having a problem when trying to pass an array back to a COM
I'm having problems to iterate twice on the same array: <? $indice=0 ?> <?php
I'm having a brain cramp... how do I initialize an array of objects properly
I'm writing a C program but I keep having problems with my array of
I'm having trouble deserializing an array in .NET MVC3, any help would be appreciated.
I'm having issues passing an array struct into a function for processing. I think
I'm having an array of data like this: $array = array( 'total_ids' => 0,

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.