BSD

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Pointer to id

    5 answers - 525 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi everybody,
    very fond of the large thread I've started with pointers, I beg your
    pardon if I ask you another very silly question.
    I've got to detach a new thread with
    The problem stands in the fact that "" accepts only "id",
    while I need to send a pointer ( PortAudioStream *stream) instead.
    If I put "stream" in detachNewThreadSelector: the debugger complains
    and halts, while if I set nil everything is ok.
    How can I bypass this awful situation?
    Many thanks to all of you.
  • No.1 | | 1223 bytes | |

    1/2/06, Sanri Parov <sanri.parov (AT) tiscali (DOT) itwrote:
    Hi everybody,

    very fond of the large thread I've started with pointers, I beg your
    pardon if I ask you another very silly question.
    I've got to detach a new thread with

    The problem stands in the fact that "" accepts only "id",
    while I need to send a pointer ( PortAudioStream *stream) instead.
    If I put "stream" in detachNewThreadSelector: the debugger complains
    and halts, while if I set nil everything is ok.
    How can I bypass this awful situation?

    The NSValue class is capable of wrapping a pointer inside an object.

    You can sometimes get away with simply casting a pointer or integer to
    id, though it may not be a good idea, but
    needs real objects
    because it retains them when the thread is detached and releases them
    when it terminates, and only real objects respond to retain and
    release messages.

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.2 | | 945 bytes | |

    Il giorno 02/gen/06, alle ore 02:21, Pontus Ilbring ha scritto:

    The NSValue class is capable of wrapping a pointer inside an object.

    You can sometimes get away with simply casting a pointer or integer to
    id, though it may not be a good idea, but
    needs real objects
    because it retains them when the thread is detached and releases them
    when it terminates, and only real objects respond to retain and
    release messages.

    mmmhhhh
    I've tried doing this:

    NSValue *value;
    value = [NSValue valueWithPointer:@encode(PortAudioStream *)];
    [value retain];
    [NSThread detachNewThreadSelector: @selector(playForSure:)
    toTarget: nil :value];

    The called selector is:
    - (void)playForSure:(PortAudioStream *)stream;
    {NSLog(@"selector called");}

    but the selector is not called in any way.
    I've tried retainig "value" but nothing
    Do you have any clues?
    Thank you again.
  • No.3 | | 1167 bytes | |

    2 jan 2006, at 11.48, Sanri Parov wrote:

    PortAudio has nothing to do with NS as it's a plain C bunch
    of functions that doesn't inherit from anything.

    Where did you get the pointer to that stream? If it's owned by some
    object, pass that object. If it's a global variable, or something you
    can look up from a global function, don't pass anything at all.

    2 jan 2006, at 12.08, Sanri Parov wrote:

    [NSThread detachNewThreadSelector: @selector(playForSure:)
    toTarget: nil :value];

    The called selector is:

    - (void)playForSure:(PortAudioStream *)stream;

    but the selector is not called in any way.

    Since you're sending the message to *nil*, that's not surprising at
    all

    Also, the method should now have this signature:
    - (void) playForSure:(NSValue *) streamPtr;

    j o a r

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.4 | | 1406 bytes | |

    02/gen/06, at 12:08, Sanri Parov wrote:

    mmmhhhh
    I've tried doing this:

    NSValue *value;
    value = [NSValue valueWithPointer:@encode(PortAudioStream *)];
    [value retain];
    [NSThread detachNewThreadSelector: @selector(playForSure:)
    toTarget: nil :value];

    Don't use @encode with valueWithPointer. It takes an actual pointer,
    not a pointer type. Also, you shouldn't retain value,
    detachNewThreadSelector will take care of it. Use something like this:

    PortAudioStream *stream;

    /* put code to initialize stream here */
    [NSThread detachNewThreadSelector: @selector(playForSure:)
    toTarget:self :[NSValue valueWithPointer:pas]];

    assuming that the object which should handle the playForSure message
    is self; otherwise, change it as needed.

    The selector should be like this:
    - (void)playForSure:(NSValue *)streamValue;
    {
    PortAudioStream *stream;
    NSAutoreleasePool *pool;

    pool = [[NSAutoreleasePool alloc] init];
    stream = [streamValue pointerValue];

    /* put your code here */

    [pool release];
    }

    Camillo

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.5 | | 1032 bytes | |

    Jan 2, 2006, at 3:08 AM, Sanri Parov wrote:
    mmmhhhh
    I've tried doing this:

    NSValue *value;
    value = [NSValue valueWithPointer:@encode(PortAudioStream *)];
    [value retain];
    [NSThread detachNewThreadSelector: @selector(playForSure:)
    toTarget: nil :value];

    (1) Don't use @encode(). valueWithPointer: just takes a raw
    pointer; it needs no information about what it is a pointing to.

    (2) You are passing nil as the target for invocation of -playForSure:
    in the detached thread. This effectively does absolutely nothing as
    there is no way for NSThread to know whose -playForSure: method
    should be invoked.

    If -playForSure: is implemented on self, then pass self as the target.

    b.bum

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com

Re: Pointer to id


max 4000 letters.
Your nickname that display:
In order to stop the spam: 6 + 5 =
QUESTION ON "BSD"

EMSDN.COM