FROM : Charlton Wilbur
DATE : Sat Dec 25 19:42:22 2004
On Dec 25, 2004, at 12:54 PM, Peter Karlsson wrote:
> What is the right way of allocating memory in Cocoa?
Well, the simplest way is to use +alloc and -init. What problem are
you trying to solve that those can't handle?
> I'm using this code at the moment.
>
> // allocate 100000 bytes for memory1_ptr
> if((memory1_ptr = malloc(100000)) == NULL)
> {
> printf("malloc memory1_ptr failed\n");
> }
That will allocate memory, but it doesn't fit the general Cocoa and
Objective-C idioms. My inclination would be to call that the *wrong*
way of going about it, but there are reasons you might want to do it.
Without knowing why you're allocating memory, or what problem you have
that +alloc/-init don't solve, I can't comment on whether that approach
is actually the right thing to do.
Charlton
--
Charlton Wilbur
<email_removed>
<email_removed>
DATE : Sat Dec 25 19:42:22 2004
On Dec 25, 2004, at 12:54 PM, Peter Karlsson wrote:
> What is the right way of allocating memory in Cocoa?
Well, the simplest way is to use +alloc and -init. What problem are
you trying to solve that those can't handle?
> I'm using this code at the moment.
>
> // allocate 100000 bytes for memory1_ptr
> if((memory1_ptr = malloc(100000)) == NULL)
> {
> printf("malloc memory1_ptr failed\n");
> }
That will allocate memory, but it doesn't fit the general Cocoa and
Objective-C idioms. My inclination would be to call that the *wrong*
way of going about it, but there are reasons you might want to do it.
Without knowing why you're allocating memory, or what problem you have
that +alloc/-init don't solve, I can't comment on whether that approach
is actually the right thing to do.
Charlton
--
Charlton Wilbur
<email_removed>
<email_removed>
| Related mails | Author | Date |
|---|---|---|
| Peter Karlsson | Dec 25, 18:54 | |
| Charlton Wilbur | Dec 25, 19:42 | |
| Prachi Gauriar | Dec 25, 22:08 | |
| Finlay Dobbie | Dec 25, 23:43 | |
| Sherm Pendley | Dec 26, 17:42 |






Cocoa mail archive

