Printing graphics plus text

2011-06-11 Thread Scott Steinman
Please forgive me if my question is stupid.  It's frustrating being a Cocoa 
noobie after 30 years of scientific programming, but I'm doing my best to learn.

I'm working on an application that displays a diagram I have drawn in a custom 
view to represent data input by the user.  I'd like to print that diagram plus 
the input values.  I've read explanations and examples in Apple's 
documentation, my library of Cocoa books, and from web searches. Each explains 
only how to print either a view graphics or a view containing text by 
instantiating an offscreen instance of that single view and redrawing its 
contents for printing. 

Unfortunately, none of them shows how to print two views containing different 
contents.  Can the offscreen view contain subviews that each know how to draw 
themselves?

Thank you in advance for your help.  Unless I run into a problem, I won't 
respond here so I don't decrease the signal to noise ratio of this list. 

Scott
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NS_BUILD_32_LIKE_64

2011-06-11 Thread Gerriet M. Denkmann
When I define NS_BUILD_32_LIKE_64=1 I can simply write:

NSUInteger u = 12;
NSLog(@u = %lu, u );

Otherwise I would need to use a cast like:
NSLog(@u = %lu, (unsigned long)u );

or even more clumsy:

#if __LP64__ 
NSLog(@u = %lu, u );
#else
NSLog(@u = %u, u );
#endif

The 64-Bit Transition Guide for Cocoa just says:
The NS_BUILD_32_LIKE_64 macro is useful when binary compatibility is not a 
concern, such as when building an application.

So: why is this NS_BUILD_32_LIKE_64 not always defined (as default) and what 
binary compatibility issues I have to be aware of?


Kind regards,

Gerriet.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NS_BUILD_32_LIKE_64

2011-06-11 Thread Lee Ann Rucker
If it's only NSLog formatting that's an issue, a trick we use for 
cross-platform printfs is a conditional macro (this is off the top of my head; 
ours is conditional on Windows or Mac/Linux):

#if __LP64__
#define FMT_NSUInt %lu
#else
#define FMT_NSUInt %u
#endif

NSLog(@u = FMT_NSUInt etc, u);


- Original Message -
From: Gerriet M. Denkmann gerr...@mdenkmann.de
To: cocoa-dev@lists.apple.com
Sent: Saturday, June 11, 2011 12:54:39 AM
Subject: NS_BUILD_32_LIKE_64

When I define NS_BUILD_32_LIKE_64=1 I can simply write:

NSUInteger u = 12;
NSLog(@u = %lu, u );

Otherwise I would need to use a cast like:
NSLog(@u = %lu, (unsigned long)u );

or even more clumsy:

#if __LP64__ 
NSLog(@u = %lu, u );
#else
NSLog(@u = %u, u );
#endif

The 64-Bit Transition Guide for Cocoa just says:
The NS_BUILD_32_LIKE_64 macro is useful when binary compatibility is not a 
concern, such as when building an application.

So: why is this NS_BUILD_32_LIKE_64 not always defined (as default) and what 
binary compatibility issues I have to be aware of?


Kind regards,

Gerriet.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/lrucker%40vmware.com

This email sent to lruc...@vmware.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NS_BUILD_32_LIKE_64

2011-06-11 Thread Quincey Morris
On Jun 11, 2011, at 00:54, Gerriet M. Denkmann wrote:

 The 64-Bit Transition Guide for Cocoa just says:
 The NS_BUILD_32_LIKE_64 macro is useful when binary compatibility is not a 
 concern, such as when building an application.
 
 So: why is this NS_BUILD_32_LIKE_64 not always defined (as default) and what 
 binary compatibility issues I have to be aware of?

AFAIK there are 2 possible points of incompatibility: (a) libraries and (b) 
plugins.

I can't think of an ABI reason why C or Objective-C code should be incompatible 
(across library/plugin boundaries where this macro had different values during 
compilation), but there may be some obscure cases where an incompatibility 
exists. For example, it might be that int and long have different structure 
alignment implications in certain architectures, even if they're the same size.

It's also possible that Objective-C runtime things will break if they depend on 
@encode-style representations of types. However, the compilers are very 
cavalier with the @encode types, and at least in 64-bit compilations @encode 
types really only tell you sizes, not C types.

Of course, C++ or Objective-C++ code is going to be incompatible, because of 
name mangling.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSInputStream created from NSData - expected it to close at end of data, did not happen

2011-06-11 Thread Jodischlange

Am 11.06.2011 um 03:19 schrieb Jens Alfke:

 
 On Jun 10, 2011, at 5:35 PM, jodischla...@gmx.de wrote:
 
 I want the TCPServer to return some data block to each client that connects. 
 I basically just want to put the bytes of the NSData object one after 
 another on the outputstream that is connected to the socket.
 Problem: I would have to save the position in the data for each client to 
 return the correct bytes to the client. At that point I thought that's what 
 streams are for. To save your current position in a blob of bytes that 
 should be read in order.
 
 Oh, so the input stream is on the server side? I didn’t realize that. Each 
 client connection handler makes a stream of the data, then checks how much 
 room is available to write to the client, reads that many from that stream 
 and writes them to the client socket?
Yes, exactly. :-)


 The simplicity is already gone, so I would be happy to try another way to 
 test the implementation as well. But I can't think of one
 
 Well, you could write this server in about five lines of Ruby or Python*. I 
 think one of the networking examples in the Ruby “pickaxe” book** is a server 
 that just sends the current time (as a line of ASCII) to any client that 
 connects.
Hm, that might be a good idea. As long as I can be sure that the stream is then 
closed after the data has been sent. 

But how difficult would it be to configure this kind of server-script from 
inside a SenTestCase?
At the moment I create different blocks of data in different SenTestCases, 
create a DataStreamingServer for that data, tell the client to connect to the 
server and let the run loop run for a second.

I don't have any experience with Python or Ruby yet (and not too much with the 
icky PHP ^^). In what way would I give the data to the script? At the moment 
I'm thinking about a command line style script that I would execute from the 
test (which doesn't sound nice) and wondering about how to hand the data object 
over to the script. But there is also a Python/Ruby Bridge, isn't there? I 
don't have experience with such bridges either. Could you then somehow mix 
Objective-C and Python code?


Joachim___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSInputStream created from NSData - expected it to close at end of data, did not happen

2011-06-11 Thread Jodischlange
Am 11.06.2011 um 05:01 schrieb Ken Thomases:

 On Jun 10, 2011, at 7:35 PM, jodischla...@gmx.de wrote:
 
 I want the TCPServer to return some data block to each client that connects. 
 I basically just want to put the bytes of the NSData object one after 
 another on the outputstream that is connected to the socket.
 Problem: I would have to save the position in the data for each client to 
 return the correct bytes to the client. At that point I thought that's what 
 streams are for. To save your current position in a blob of bytes that 
 should be read in order.
 Solution: Create a new NSInputStream (independent from the input stream of 
 the TCPServer. That's why I talked about the data input stream, the input 
 stream that reads the bytes of the data object) for each incoming 
 connection. Guessing that after the NSInputStream based on the data is open 
 it won't have any problems reading the data I only wait for the output 
 stream to have space available and whenever it has I read some bytes from 
 the data input stream and write them on the server output stream. I 
 completely ignore the server input stream (except for logging the received 
 data, when searching for bugs).
 
 When the client can accept data, you can just read from the input stream.  If 
 you get a zero-length read, then the input stream is exhausted.  
 You may not get an event for that.  
Yes that's my problem. And that's why I close the stream now as soon as it does 
not have any more bytes available.

 In fact, the input stream need not be scheduled on a run loop and, if it's 
 not, the delegate won't get any calls.
But I did schedule it in a run loop and I do get NSStreamEventOpenCompleted and 
NSStreamEventHasBytesAvailable. I just don't get and 
NSStreamEventEndEncountered. Which would not be a big problem for the 
datastream. But:

 The events and the delegate are for asynchronous events in the stream, and 
 there are none for a stream based on a data object.
I also have the streams connected to the TCP-connection. When I close the 
datastream (and I checked with the debugger, that I actually do) I also close 
the output stream of the TCP connection on the server side. At that point I 
would expect the input stream connected to the socket on the client side to be 
closed as well. I don't know whether it is closed at that point, but at least I 
do not get an NSStreamEventEndEncountered event on the client side. 
And I can't think of a reason for that.

The TCP connection of the client and server is local (127.0.0.1 as host address 
for the client, with some 3 port) and the data transfer seems to work, I 
checked with the debugger, that I get the bytes I expect to receive. The only 
thing that is missing is the NSStreamEvenEndEncountered.

That's why I think the problem is either stream related or related to my 
(wrong?) understanding of streams.

Best regards,
Joachim
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


visibleRect returns bogus results, why?

2011-06-11 Thread Alexander Reichstadt
Hi,


I have a view with view controller. The controller receives scroll changes. 
visibleRect returns bogus, so I tracked it with NSLog and confirmed this.

I use this code:
 NSRect theRect = [[self view] visibleRect];
 NSLog(@%@,NSStringFromRect(theRect));  

When I scroll using the scrollwheel or arrows of the scrollbar, it looks good

2011-06-11 14:34:06.089 App[20913:903] {{0, 0}, {10, 344}

When I click onto the dot inside the scrollbar and drag it to another position, 
it turns to bogus:
2011-06-11 14:34:09.108 App[20913:903] {{0, 1.21354e+09}, {10, 344}}

I also tried:
 NSRect theRect = [[[self view] enclosingScrollView] documentVisibleRect];

Same result. Why



Thanks
Alex
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Solved: visibleRect returns bogus results, why?

2011-06-11 Thread Alexander Reichstadt
Never mind, what works reliably is:

NSRect theRect = [[[self view] enclosingScrollView] visibleRect];


Am 11.06.2011 um 14:39 schrieb Alexander Reichstadt:

 Hi,
 
 
 I have a view with view controller. The controller receives scroll changes. 
 visibleRect returns bogus, so I tracked it with NSLog and confirmed this.
 
 I use this code:
  NSRect theRect = [[self view] visibleRect];
  NSLog(@%@,NSStringFromRect(theRect));  
 
 When I scroll using the scrollwheel or arrows of the scrollbar, it looks good
 
 2011-06-11 14:34:06.089 App[20913:903] {{0, 0}, {10, 344}
 
 When I click onto the dot inside the scrollbar and drag it to another 
 position, it turns to bogus:
 2011-06-11 14:34:09.108 App[20913:903] {{0, 1.21354e+09}, {10, 344}}
 
 I also tried:
  NSRect theRect = [[[self view] enclosingScrollView] documentVisibleRect];
 
 Same result. Why
 
 
 
 Thanks
 Alex

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Solved: visibleRect returns bogus results, why?

2011-06-11 Thread Alexander Reichstadt
No, it's not solved. This works, because it always gives me the same rectangle. 
As far as I can see this call is broken. As soon as a user drags the scrollbar 
freely, the numbers go all bunkers as if the visible rectangle had an origin 
which was a hundred miles down the screen. As a result rowsInRect for tableview 
doesn't work neither and returns also useless results. Stupid. Is this normal 
and a known bug, or am I missing something?

Am 11.06.2011 um 14:49 schrieb Alexander Reichstadt:

 Never mind, what works reliably is:
 
 NSRect theRect = [[[self view] enclosingScrollView] visibleRect];
 
 
 Am 11.06.2011 um 14:39 schrieb Alexander Reichstadt:
 
 Hi,
 
 
 I have a view with view controller. The controller receives scroll changes. 
 visibleRect returns bogus, so I tracked it with NSLog and confirmed this.
 
 I use this code:
  NSRect theRect = [[self view] visibleRect];
  NSLog(@%@,NSStringFromRect(theRect));  
 
 When I scroll using the scrollwheel or arrows of the scrollbar, it looks good
 
 2011-06-11 14:34:06.089 App[20913:903] {{0, 0}, {10, 344}
 
 When I click onto the dot inside the scrollbar and drag it to another 
 position, it turns to bogus:
 2011-06-11 14:34:09.108 App[20913:903] {{0, 1.21354e+09}, {10, 344}}
 
 I also tried:
  NSRect theRect = [[[self view] enclosingScrollView] documentVisibleRect];
 
 Same result. Why
 
 
 
 Thanks
 Alex
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Close: Solved: visibleRect returns bogus results, why?

2011-06-11 Thread Alexander Reichstadt
My bad, I made an NSInteger into an NSUInteger the wrong way hence returning an 
amount of rows for an NSTableview that was incorrect, so the tableview really 
grew to that size.

Am 11.06.2011 um 15:03 schrieb Alexander Reichstadt:

 No, it's not solved. This works, because it always gives me the same 
 rectangle. As far as I can see this call is broken. As soon as a user drags 
 the scrollbar freely, the numbers go all bunkers as if the visible rectangle 
 had an origin which was a hundred miles down the screen. As a result 
 rowsInRect for tableview doesn't work neither and returns also useless 
 results. Stupid. Is this normal and a known bug, or am I missing something?
 
 Am 11.06.2011 um 14:49 schrieb Alexander Reichstadt:
 
 Never mind, what works reliably is:
 
NSRect theRect = [[[self view] enclosingScrollView] visibleRect];
 
 
 Am 11.06.2011 um 14:39 schrieb Alexander Reichstadt:
 
 Hi,
 
 
 I have a view with view controller. The controller receives scroll changes. 
 visibleRect returns bogus, so I tracked it with NSLog and confirmed this.
 
 I use this code:
 NSRect theRect = [[self view] visibleRect];
 NSLog(@%@,NSStringFromRect(theRect));  
 
 When I scroll using the scrollwheel or arrows of the scrollbar, it looks 
 good
 
 2011-06-11 14:34:06.089 App[20913:903] {{0, 0}, {10, 344}
 
 When I click onto the dot inside the scrollbar and drag it to another 
 position, it turns to bogus:
 2011-06-11 14:34:09.108 App[20913:903] {{0, 1.21354e+09}, {10, 344}}
 
 I also tried:
 NSRect theRect = [[[self view] enclosingScrollView] documentVisibleRect];
 
 Same result. Why
 
 
 
 Thanks
 Alex
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/lxr%40mac.com
 
 This email sent to l...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Nick
Hi

In Mac OS 10.6 (Snow Leopard) it is pretty simple to launch another
application from within my application (in a way that my application becomes
a parent process to the child) - i either may call [NSTask launchTask], or
call fork()/exec() - either way, my process and the launched
process-application are related by parent-child (and i can use pipes or
socketpair for them to communicate).

In Mac OS 10.5 (Leopard) launching a process is simple as well, unless this
process is an Application (a bundle, that is supposed to have an icon in
dock). If i start it with NSTask, i get Application not responding icon in
dock (but the application works fine, only this behvior in Dock is very
irritating). I suppose this is happening because usually start of an
application is supposed to be performed by LaunchServices (my app has to
delegate this job to LS, and therefore my process is not a parent of this
newly spawned process).

Is there any way to remain a parent of a just launched application?

I know that Mac OS 10.5 Leopard is deprecated, but i can't help it - my boss
wants Leopard support.

Thank you!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Ken Thomases
On Jun 11, 2011, at 10:32 AM, Nick wrote:

 In Mac OS 10.6 (Snow Leopard) it is pretty simple to launch another
 application from within my application (in a way that my application becomes
 a parent process to the child) - i either may call [NSTask launchTask], or
 call fork()/exec() - either way, my process and the launched
 process-application are related by parent-child (and i can use pipes or
 socketpair for them to communicate).
 
 In Mac OS 10.5 (Leopard) launching a process is simple as well, unless this
 process is an Application (a bundle, that is supposed to have an icon in
 dock). If i start it with NSTask, i get Application not responding icon in
 dock (but the application works fine, only this behvior in Dock is very
 irritating). I suppose this is happening because usually start of an
 application is supposed to be performed by LaunchServices (my app has to
 delegate this job to LS, and therefore my process is not a parent of this
 newly spawned process).
 
 Is there any way to remain a parent of a just launched application?

Why do you care if it's the parent?  What feature(s) of the parent-child 
relationship is (are) important?  Maybe what you're trying to achieve can be 
accomplished in some other manner while still using NSWorkspace or Launch 
Services to launch the application (which is the right way).

If it's just inter-process communication, there are other options.  For 
example, use Bonjour for the parent to advertise its service and for the child 
to find and connect to it.  Or use Unix domain sockets with a path that is 
known to both.  Using Launch Services, you can pass an Apple Event descriptor 
with additional parameter information, which the child can retrieve.  (The 
methods of NSWorkspace claim to support this, but I've found them to be buggy 
in this regard.)  Etc.

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Nick
Ken,
i have an agent and a corresponding per-agent process (this per-agent
process, apart from doing its main job and displaying gui when its clicked,
displays an icon in dock which can change colors).  Of course, the agent is
spawned for every logged in user.
I found parent-child connected (socketpair) sockets/pipes to be the easiest
way to set up a conversation between an agent and that peruser application
in Dock.  And in Snow Leopard it works.

This per user idea does not let me use any advertisement-based  IPCs (like
user domain sockets or bonjour). I need some per user only IPC - so other
user's instance of the process does  not interfere with the current user's
one.

I've heard that Mach Ports can be set to be seen only in the current login
session (i.e., by current user's apps), but search led me to conclusion this
is rather a messy/few documented (for usermode applications) topic and it
behaves differently  for Leopard and Snow Leopard due to some changes in
bootstrap context

2011/6/11 Ken Thomases k...@codeweavers.com

 On Jun 11, 2011, at 10:32 AM, Nick wrote:

 Why do you care if it's the parent?  What feature(s) of the parent-child
 relationship is (are) important?  Maybe what you're trying to achieve can be
 accomplished in some other manner while still using NSWorkspace or Launch
 Services to launch the application (which is the right way).

 If it's just inter-process communication, there are other options.  For
 example, use Bonjour for the parent to advertise its service and for the
 child to find and connect to it.  Or use Unix domain sockets with a path
 that is known to both.  Using Launch Services, you can pass an Apple Event
 descriptor with additional parameter information, which the child can
 retrieve.  (The methods of NSWorkspace claim to support this, but I've found
 them to be buggy in this regard.)  Etc.

 Regards,
 Ken


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Kyle Sluder
On Sat, Jun 11, 2011 at 9:59 AM, Nick eveningn...@gmail.com wrote:
 I found parent-child connected (socketpair) sockets/pipes to be the easiest
 way to set up a conversation between an agent and that peruser application
 in Dock.  And in Snow Leopard it works.

Okay, it makes one thing easy (IPC) and another thing harder (making
your app actually function). :)

 This per user idea does not let me use any advertisement-based  IPCs (like
 user domain sockets or bonjour ). I need some per user only IPC - so other
 user's instance of the process does  not interfere with the current user's
 one.

 
 I've heard that Mach Ports can be set to be seen only in the current login
 session (i.e., by current user's apps), but search led me to conclusion this
 is rather a messy/few documented (for usermode applications) topic and it
 behaves differently  for Leopard and Snow Leopard due to some changes in
 bootstrap context

The per-user bootstrap namespace has existed since Leopard.
http://developer.apple.com/library/mac/#technotes/tn2005/tn2083%23SECNAMESPACEHIERARCHY

Granted, using Mach facilities directly is considered bad form by
Apple, but I'd suggest experimenting with configuring your launchd
plist and using NSConnection to set up DO. But if anyone knows of any
gremlins, it would be helpful to mention them.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Ken Thomases
On Jun 11, 2011, at 11:59 AM, Nick wrote:

 i have an agent and a corresponding per-agent process (this per-agent 
 process, apart from doing its main job and displaying gui when its clicked, 
 displays an icon in dock which can change colors).  Of course, the agent is 
 spawned for every logged in user.

You should consider reversing the relationship between the agent and the GUI 
app.  Consider making your agent a launchd agent, which is launched on demand 
whenever the GUI app requests its services (or when some other 
launchd-supported event occurs). To the GUI app, it appears as though the agent 
is always available.

 I found parent-child connected (socketpair) sockets/pipes to be the easiest 
 way to set up a conversation between an agent and that peruser application in 
 Dock.  And in Snow Leopard it works.

If it works in Snow Leopard, it's by accident and likely to fail in 
configurations you haven't thought to test or in future OS releases.  You 
should be using Launch Services to launch applications.

 This per user idea does not let me use any advertisement-based  IPCs (like 
 user domain sockets or bonjour).

Unix domain sockets can be in user-specific locations within the file system, 
like the temporary directory.

 I need some per user only IPC - so other user's instance of the process 
 does  not interfere with the current user's one.
 
 I've heard that Mach Ports can be set to be seen only in the current login 
 session (i.e., by current user's apps), but search led me to conclusion this 
 is rather a messy/few documented (for usermode applications) topic and it 
 behaves differently  for Leopard and Snow Leopard due to some changes in 
 bootstrap context   

You don't have to use raw Mach ports.  You can use CFMessagePort or NSMachPort. 
 If you're thinking of TN2083 
http://developer.apple.com/library/mac/#technotes/tn2083/, there are 
recommendations against Mach-port-based APIs but they're only in regards to 
daemons, not agents, precisely because daemons are non-user-specific.  For 
agents, they are appropriate.  (See the IMPORTANT note just above the Mach 
Considered Harmful section.)

You should consider Distributed Objects, or at least the techniques it uses 
with NSConnection and NSPort-derived objects.  See the Distributed Objects 
Programming Topics 
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html.
  If you aren't comfortable using it for the bulk of your IPC, maybe it will 
just be useful to exchange the name of a Unix domain socket between the server 
and the client.

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Greg Guerin

Nick wrote:

This per user idea does not let me use any advertisement-based   
IPCs (like
user domain sockets or bonjour). I need some per user only IPC -  
so other
user's instance of the process does  not interfere with the current  
user's

one.



A Unix domain socket can be placed anywhere in the file-system,  
AFAIK.  So put it in the user's home directory, probably best in a  
sub-dir like ~/Library/Application Support/YourAppNameHere/.  A  
location under user's home dir also ensures that access permissions  
are applied when addressing the socket.  The name need not be  
advertised if both parties already know its pathname.


http://en.wikipedia.org/wiki/Unix_domain_socket
UNIX domain sockets use the file system as address name space.

Also, Bonjour service type names may incorporate unique identifiers.   
For example, the user-name or user id, or a GUID known to both  
parties.  (Obey limits on service type name length, and consider  
vulnerability to spoofing attacks.)


  -- GG___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Why Wasn't Memory Collected?

2011-06-11 Thread Bing Li
Dear all,

I sent a large number, e.g., 200,000, of XML to a remote node. Each time,
the XML was created by the following method. Because of the large number, I
noticed the consumed memory was large (more then 1G!) from Activity Monitor.
Even after the sending was done, the memory was still kept in a high degree
without any decreasing.

However, the method below should be able to collect the consumed memory,
right? Why wasn't memory collected?

I appreciate so much for your help!

Best regards,
Bing

+ (const char *)createSendMessage:(NSString *)sourcePeerKey SPN:(NSString
*)sourcePeerName DPK:(NSString *)destinationPeerKey DPN:(NSString
*)destinationPeerName MSG:(NSString *)message
{
NSXMLElement *root = [NSXMLNode elementWithName:@MessageRoot];
NSXMLDocument *xmlDoc = [[NSXMLDocument alloc]
initWithRootElement:root];
[xmlDoc setVersion:@1.0];
[xmlDoc setCharacterEncoding:@UTF-8];

NSXMLElement *messageKeyElement = [NSXMLNode elementWithName:@
MessageKey];
[root addChild:messageKeyElement];
[messageKeyElement addChild:[NSXMLNode
textWithStringValue:[Utilities createUniqueKey]]];

NSXMLElement *commandElement = [NSXMLNode elementWithName:@
Command];
[root addChild:commandElement];
[commandElement addChild:[NSXMLNode textWithStringValue:@
SendMessage]];

NSXMLElement *sourcePeerKeyElement = [NSXMLNode elementWithName:@
SOURCE_PEER_KEY];
[root addChild:sourcePeerKeyElement];
[sourcePeerKeyElement addChild:[NSXMLNode
textWithStringValue:sourcePeerKey]];

NSXMLElement *sourcePeerNameElement = [NSXMLNode elementWithName:@
XML.SOURCE_PEER_NAME];
[root addChild:sourcePeerNameElement];
[sourcePeerNameElement addChild:[NSXMLNode
textWithStringValue:sourcePeerName]];

NSXMLElement *destinationPeerKeyElement = [NSXMLNode
elementWithName:@XML.DESTINATION_PEER_KEY];
[root addChild:destinationPeerKeyElement];
[destinationPeerKeyElement addChild:[NSXMLNode
textWithStringValue:destinationPeerKey]];

NSXMLElement *destinationPeerNameElement = [NSXMLNode
elementWithName:@XML.DESTINATION_PEER_NAME];
[root addChild:destinationPeerNameElement];
[destinationPeerNameElement addChild:[NSXMLNode
textWithStringValue:destinationPeerName]];

NSXMLElement *messageElement = [NSXMLNode elementWithName:@
XML.MESSAGE];
[root addChild:messageElement];
[messageElement addChild:[NSXMLNode textWithStringValue:message]];

NSData *data = [xmlDoc XMLData];
NSString *xmlStr = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
xmlStr = [xmlStr stringByAppendingString:@\n];
const char *xmlChar = [xmlStr UTF8String];

[xmlDoc release];
return xmlChar;
}
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Nick
Thank you.

I am sorry, I should have tested how it behaves with ordinary applications
before.
I just realized that I was wrong about the source of the issue i am having.
[NSTask launchTaskForPath] works perfectly on both systems, for both GUI
(bundled .app) and command line applications - it works, because we are able
to start an application from a Terminal (and terminal fork()/exec() 's the
binary). So, [NSTask] works, unless we decide to call it from a
spawned-by-launchd application (i.e, an agent). When I do this, an
application appears to be spawned in a different boostrap context (or
something like that). Due to some change in bootstrap spaces, an agent can
spawn ordinary-user's processes without any side effects in Snow Leopard -
Apple moved everything related to a user into one bootstrap space (in
contrary to several pink rectangles that are shown in the Daemons  Agents
technote). But not in Leopard.

The only option i have, i guess, is to ask Launch Services (or NSWorkspace)
to launch my app, as suggested.

2011/6/11 Greg Guerin glgue...@amug.org

 Nick wrote:

  This per user idea does not let me use any advertisement-based  IPCs
 (like
 user domain sockets or bonjour ). I need some per user only IPC - so
 other

 user's instance of the process does  not interfere with the current user's
 one.



 A Unix domain socket can be placed anywhere in the file-system, AFAIK.  So
 put it in the user's home directory, probably best in a sub-dir like
 ~/Library/Application Support/YourAppNameHere/.  A location under user's
 home dir also ensures that access permissions are applied when addressing
 the socket.  The name need not be advertised if both parties already know
 its pathname.

 http://en.wikipedia.org/wiki/Unix_domain_socket
 UNIX domain sockets use the file system as address name space.

 Also, Bonjour service type names may incorporate unique identifiers.  For
 example, the user-name or user id, or a GUID known to both parties.  (Obey
 limits on service type name length, and consider vulnerability to spoofing
 attacks.)

  -- GG___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/eveningnick%40gmail.com

 This email sent to eveningn...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Why Wasn't Memory Collected?

2011-06-11 Thread Nick Zitzmann

On Jun 11, 2011, at 12:03 PM, Bing Li wrote:

 Dear all,
 
 I sent a large number, e.g., 200,000, of XML to a remote node. Each time,
 the XML was created by the following method. Because of the large number, I
 noticed the consumed memory was large (more then 1G!) from Activity Monitor.
 Even after the sending was done, the memory was still kept in a high degree
 without any decreasing.
 
 However, the method below should be able to collect the consumed memory,
 right?

Not always.

 Why wasn't memory collected?

If you're not using GC, and you're creating a lot of temporary objects in a 
loop, then you'll need to manually create and drain an autorelease pool inside 
that loop while being careful not to delete objects you don't want to delete. I 
find that it helps to use Instruments' object allocation tool, and watch for 
places where memory usage increases and then suddenly falls off. Those are the 
places where you need to set inline pools.

If you're using GC, then this will not be a problem, although if you create and 
drain an autorelease pool anyway, draining the pool will force the collector to 
begin if it hasn't already.

Nick Zitzmann
http://www.chronosnet.com/



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Getting CGColor components

2011-06-11 Thread Development
According to all the examples I have found the following code should give me 
the RGB components of any UIColor.CGColor I pass to it

However I get back a scrambled and often inaccurate array of color values which 
turns out to be useless.

CGFloat colors[[widgetArray count]*4];



id * item;
int idx=0;
for (item in widgetArray) {



const CGFloat *comp = 
CGColorGetComponents(item.backgroundColor.CGColor);  
const CGFloat *c = CGColorGetComponents(item.backgroundColor.CGColor); 

colors[idx] = comp[0];
   
colors[++idx] = comp[1];

colors[++idx] = comp[2];
 
colors[++idx] = 
c[CGColorGetNumberOfComponents(item.backgroundColor.CGColor)-1];

idx++;

}___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Getting CGColor components

2011-06-11 Thread Development
:\ 

I think I have it figured out

All colors work except white and black.


I had to detect those and build the rgb manually

On Jun 11, 2011, at 4:12 PM, Development wrote:

 According to all the examples I have found the following code should give me 
 the RGB components of any UIColor.CGColor I pass to it
 
 However I get back a scrambled and often inaccurate array of color values 
 which turns out to be useless.
 
CGFloat colors[[widgetArray count]*4];
 
 
 
id * item;
int idx=0;
for (item in widgetArray) {
 
 
 
const CGFloat *comp = 
 CGColorGetComponents(item.backgroundColor.CGColor);  
const CGFloat *c = CGColorGetComponents(item.backgroundColor.CGColor); 
 
colors[idx] = comp[0];
 
colors[++idx] = comp[1];
 
colors[++idx] = comp[2];
 
colors[++idx] = 
 c[CGColorGetNumberOfComponents(item.backgroundColor.CGColor)-1];
 
idx++;
 
}___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/development%40fornextsoft.com
 
 This email sent to developm...@fornextsoft.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iOS: encoding a custom view with a shape in it

2011-06-11 Thread Steve Christensen
How do the results differ between what you saw before and after saving the 
document? Is everything wrong? or just the scaling, the rotation, what?

And to draw an object, are you using an affine transform just to rotate it or 
for scaling and/or translation as well?


On Jun 9, 2011, at 4:25 PM, Development wrote:

 This app allows users to do a number of graphical things. On of those things 
 is to draw rectangles and ellipses.
 
 No it would not be complete if they could not resize and rotate these shapes. 
 Thus the features exist.
 
 The problem comes when I freeze dry the object.
 I encode it exactly as it exists at the moment the saveDocument: option is 
 invoked. 
 colors, frame,rotation etc
 logging these values confirms them
 
 When I unfreeze it, well the values remain identical. hence I know the save 
 worked.
 
 I initialize the object with the decoded rectangle for the frame
 I then apply the transition to rotate it to the correct angle.
 
 hmm the result looks nothing like the initial item did at save time
 
 So I've been looking at this very closely... Is this happening because simply 
 applying the last known frame and angle does not mean it will match?
 If this is the case, does it mean then that in order to preserve the exact 
 state, I must not only save all the data about the object but an array of 
 every change made to the object such as resizes and rotations in order to get 
 the correct result?
 
 My bandaid is to convert the view in to a UIImage and save the image. This 
 fixes the problem however the downside is that special effects that can be 
 applied to rectangles and ellipses are not available on reload.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iOS: encoding a custom view with a shape in it

2011-06-11 Thread Steve Christensen
And also to clarify, are you freeze drying a view or the objects it draws? 
You should be doing the latter since that's part of your model.


On Jun 11, 2011, at 6:47 PM, Steve Christensen wrote:

 How do the results differ between what you saw before and after saving the 
 document? Is everything wrong? or just the scaling, the rotation, what?
 
 And to draw an object, are you using an affine transform just to rotate it or 
 for scaling and/or translation as well?
 
 
 On Jun 9, 2011, at 4:25 PM, Development wrote:
 
 This app allows users to do a number of graphical things. On of those things 
 is to draw rectangles and ellipses.
 
 No it would not be complete if they could not resize and rotate these 
 shapes. Thus the features exist.
 
 The problem comes when I freeze dry the object.
 I encode it exactly as it exists at the moment the saveDocument: option is 
 invoked. 
 colors, frame,rotation etc
 logging these values confirms them
 
 When I unfreeze it, well the values remain identical. hence I know the save 
 worked.
 
 I initialize the object with the decoded rectangle for the frame
 I then apply the transition to rotate it to the correct angle.
 
 hmm the result looks nothing like the initial item did at save time
 
 So I've been looking at this very closely... Is this happening because 
 simply applying the last known frame and angle does not mean it will match?
 If this is the case, does it mean then that in order to preserve the exact 
 state, I must not only save all the data about the object but an array of 
 every change made to the object such as resizes and rotations in order to 
 get the correct result?
 
 My bandaid is to convert the view in to a UIImage and save the image. This 
 fixes the problem however the downside is that special effects that can be 
 applied to rectangles and ellipses are not available on reload.
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Printing graphics plus text

2011-06-11 Thread Eli Bach

On Jun 10, 2011, at 11:58 PM, Scott Steinman wrote:

 Please forgive me if my question is stupid.  It's frustrating being a Cocoa 
 noobie after 30 years of scientific programming, but I'm doing my best to 
 learn.
 
 I'm working on an application that displays a diagram I have drawn in a 
 custom view to represent data input by the user.  I'd like to print that 
 diagram plus the input values.  I've read explanations and examples in 
 Apple's documentation, my library of Cocoa books, and from web searches. Each 
 explains only how to print either a view graphics or a view containing text 
 by instantiating an offscreen instance of that single view and redrawing its 
 contents for printing. 
 
 Unfortunately, none of them shows how to print two views containing different 
 contents.  Can the offscreen view contain subviews that each know how to draw 
 themselves?
 
 Thank you in advance for your help.  Unless I run into a problem, I won't 
 respond here so I don't decrease the signal to noise ratio of this list. 

Scott,

Yes, the common way would be to create a superview, with multiple subviews (ie, 
with the diagram view and a view with the text values, laid out how you want 
them to print), then print the superview.

Another method some people use to print is to use a WebView, as you can just 
generate very basic html (including graphics), and then use CSS to 
format/arrange it properly.

Eli

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


layoutSubviews doesn't always work (iOS 4.3 on iPad Simulator)

2011-06-11 Thread Brian Bruinewoud
Hi All,

I have an app that consists of a scroll view subclass which contains a single 
subview. In the scroll view subclass I override layoutSubviews based on Apple 
sample code (see below). The intention of layoutSubviews is to centre the 
subview in the scrollview when the subview is smaller than the scrollview's 
display area.

There are three circumstances where the layoutSubviews is called but in one of 
them the visual results are incorrect.

If I pinch to zoom, the layout looks correct. 
scrollViewDidEndZooming:withView:forScaleL contains a single line of code that 
calls rescaleTo:animated:
[ rescaleTo: myScale * scale animated: NO ];

If I change the frame of the subview, the layout looks correct.
This is called automatically by the framework because I have called 
setNeedsLayout when I resized the subview.

If I attempt to reset the zoom to scale = 1, the layout is not centred if the 
view was bigger than the display area prior to attempting the rescale.
This is done by calling rescaleTo:animated: directly.
[ rescaleTo: 1.0 animated: YES ];

The animated: parameter only affects the contents of the subview and setting it 
to NO for all calls to this method doesn't change the results.

When I trace through layoutSubviews, the input (self.bounds.size and 
myCurrentView.frame) and output (frameToCentre) values are the same in all 
three cases, but only in the third does it not centre properly. Note that the 
subview does change position, though. 


Here is the code for layoutSubviews:

- (void)layoutSubviews 
{
[super layoutSubviews];

// center the image as it becomes smaller than the size of the screen

CGSize boundsSize = self.bounds.size;  // 1024 x 704
CGRect frameToCenter = myCurrentView.frame;  // 240 x 100 @ ( 0, 0 )

// center horizontally
if( frameToCenter.size.width  boundsSize.width )
frameToCenter.origin.x = ( boundsSize.width - frameToCenter.size.width  
 ) / 2;
else
frameToCenter.origin.x = 0;

// center vertically
if( frameToCenter.size.height  boundsSize.height )
frameToCenter.origin.y = ( boundsSize.height - 
frameToCenter.size.height ) / 2;
else
frameToCenter.origin.y = 0;

myCurrentView.frame = frameToCenter; // 240 x 100 @ ( 392, 302 )
}

Any ideas where I should look or what might be causing the behaviour?

Thanks,
Brian.___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: tools for writing help books

2011-06-11 Thread Martin Hewitson
I've been using iWeb together with this link:

http://www.ehow.com/how_7515811_do-add-xcode-project.html

Martin

On 10, Jun, 2011, at 01:14 AM, Matt Neuburg wrote:

 On Wed, 08 Jun 2011 09:33:50 +0200, Michael Thon m...@michaelrthon.com said:
 What tools to y'all recommend for writing content for the help viewer on Mac 
 OS? Do you write them directly in html/xhtml?
 
 Yeah, I rolled my own, RubyFrontier:
 
 http://www.apeth.com/RubyFrontierDocs/
 
 I've written some very extensive help viewer app documentation with it, plus 
 I use it to maintain all my Web sites, so clearly I think it's a powerful and 
 flexible tool; on the other hand it's kind of quirky in that it's modeled 
 after UserLand Frontier's website framework which is not everyone's cup of 
 tea. However, it's free and open source, and it's Ruby so you get to use 
 whatever cool Ruby tools you feel like. I write in kramdown and HAML and SASS 
 and things like that, so I'm not doing much manual HTML. m.
 
 --
 matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
 A fool + a tool + an autorelease pool = cool!
 Programming iOS 4!
 http://www.apeth.net/matt/default.html#iosbook___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/martin.hewitson%40aei.mpg.de
 
 This email sent to martin.hewit...@aei.mpg.de


Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer 
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: martin.hewit...@aei.mpg.de
WWW: http://www.aei.mpg.de/~hewitson






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Why Wasn't Memory Collected?

2011-06-11 Thread Bing Li
Dear Nick,

I appreciate so much for your reply!

I add a sub-autoreleasepool immediately outside the method that created XML.
Once if the XML is sent, the memory should be released, right? Now the
amount of memory consumed is very limited, almost no change in Activity
Monitor.

So I guess sub-autoreleasepool is important. We should not depend on the
most high level autoreleasepool to collect memory. Am I right?

Thanks,
Bing

On Sun, Jun 12, 2011 at 7:12 AM, Nick Zitzmann n...@chronosnet.com wrote:


 On Jun 11, 2011, at 12:03 PM, Bing Li wrote:

  Dear all,
 
  I sent a large number, e.g., 200,000, of XML to a remote node. Each time,
  the XML was created by the following method. Because of the large number,
 I
  noticed the consumed memory was large (more then 1G!) from Activity
 Monitor.
  Even after the sending was done, the memory was still kept in a high
 degree
  without any decreasing.
 
  However, the method below should be able to collect the consumed memory,
  right?

 Not always.

  Why wasn't memory collected?

 If you're not using GC, and you're creating a lot of temporary objects in a
 loop, then you'll need to manually create and drain an autorelease pool
 inside that loop while being careful not to delete objects you don't want to
 delete. I find that it helps to use Instruments' object allocation tool, and
 watch for places where memory usage increases and then suddenly falls off.
 Those are the places where you need to set inline pools.

 If you're using GC, then this will not be a problem, although if you create
 and drain an autorelease pool anyway, draining the pool will force the
 collector to begin if it hasn't already.

 Nick Zitzmann
 http://www.chronosnet.com/




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Why Wasn't Memory Collected?

2011-06-11 Thread Nick Zitzmann

On Jun 11, 2011, at 11:39 PM, Bing Li wrote:

 I add a sub-autoreleasepool immediately outside the method that created XML. 
 Once if the XML is sent, the memory should be released, right? Now the amount 
 of memory consumed is very limited, almost no change in Activity Monitor.
 
 So I guess sub-autoreleasepool is important. We should not depend on the most 
 high level autoreleasepool to collect memory. Am I right?

No, you can depend on it to collect memory, but you need to run your own pools 
if you need to create and get rid of large amounts of temporary objects. And 
you're going to need to use Instruments' object alloc instrument to figure out 
where your code is creating large amounts of temporary objects. Do not use 
Activity Monitor as a profiling tool.

Nick Zitzmann
http://www.chronosnet.com/



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Why Wasn't Memory Collected?

2011-06-11 Thread Stephen J. Butler
On Sat, Jun 11, 2011 at 1:03 PM, Bing Li lbl...@gmail.com wrote:
        NSData *data = [xmlDoc XMLData];
        NSString *xmlStr = [[[NSString alloc] initWithData:data
 encoding:NSUTF8StringEncoding] autorelease];
        xmlStr = [xmlStr stringByAppendingString:@\n];
        const char *xmlChar = [xmlStr UTF8String];

        [xmlDoc release];
        return xmlChar;
 }

If you're using your own autorelease pools now, be careful about the
lifetime of your return value (xmlChar)! It will only live as long as
xmlStr lives. For example, this would be incorrect:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const char *str = [self createSendMessage:...];
[pool release];
// do something with str

You'll want to strdup() the return value to make sure it lives after
the pool is released, but then you also need to remember to free()
your strdup() value.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com