<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: Can I make a call to make a new instance fail safely</title>
		<atom:link href="http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 17:06:04 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/#post-64040</guid>
					<title><![CDATA[Can I make a call to make a new instance fail safely]]></title>
					<link>http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/#post-64040</link>
					<pubDate>Mon, 20 Aug 2012 16:38:31 +0000</pubDate>
					<dc:creator>AlexHarker</dc:creator>

					<description>
						<![CDATA[
						<p>I am creating an object with large variable t_atom arrays as storage for attributes.</p>
<p>In order to allocate memory for the storage I am calling a memory allocator in the new routine. Assuming this fails, what is a safe way to prevent my object from being created, as I have no way of telling max that the attributes should not be accessed?<br />
The attributes have a custom setter in case it is relevant.</p>
<p>I assume returning a null pointer in new might work, but should I clean-up the object allocation first?</p>
<p>Alex</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/#post-230982</guid>
					<title><![CDATA[Re: Can I make a call to make a new instance fail safely]]></title>
					<link>http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/#post-230982</link>
					<pubDate>Mon, 20 Aug 2012 17:22:27 +0000</pubDate>
					<dc:creator>nicolas danet</dc:creator>

					<description>
						<![CDATA[
						<p>Hi, </p>
<p>Learning C long time ago i asked something more or less about that : <a href="http://cycling74.com/forums/topic.php?id=23093" rel="nofollow">http://cycling74.com/forums/topic.php?id=23093</a></p>
<p>Now, i do that :</p>
<pre><code>void *zoulou_new(t_symbol *s, long argc, t_atom *argv)
{
    t_zoulou *x = NULL;

    if (x = (t_zoulou *)object_alloc(zoulou_class)) {
    //
    x->values = (long *)sysmem_newptr(sizeof(long) * MAXIMUM_SIZE_LIST);
    x->factorOracle = pizFactorOracleNew(0, NULL);

    if (x->values &#038;&#038; x->factorOracle) {

        x->straightRatio     = DEFAULT_STRAIGHT;
        x->backwardThreshold = DEFAULT_BACKWARD;

        x->rightOutlet = outlet_new(x, NULL);
        object_obex_store((void *)x, zoulou_sym_dumpout, (t_object *)x->rightOutlet);
        x->leftOutlet = listout((t_object *)x);

        systhread_mutex_new(&#038;x->algorithmMutex, SYSTHREAD_MUTEX_NORMAL);

        attr_args_process(x, argc, argv);

    } else {
        object_free(x);
        x = NULL;
    }
    //
    }

    return x;
}

void zoulou_free(t_zoulou *x)
{
    if (x->values) {
        sysmem_freeptr(x->values);
    }

    pizFactorOracleFree(x->factorOracle);

    if (x->algorithmMutex) {
        systhread_mutex_free(x->algorithmMutex);
    }
}</code></pre><p>HTH</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/#post-230983</guid>
					<title><![CDATA[Re: Can I make a call to make a new instance fail safely]]></title>
					<link>http://cycling74.com/forums/topic/can-i-make-a-call-to-make-a-new-instance-fail-safely/#post-230983</link>
					<pubDate>Fri, 24 Aug 2012 20:15:39 +0000</pubDate>
					<dc:creator>tap</dc:creator>

					<description>
						<![CDATA[
						<p>Hi Alex,</p>
<p>Yes, you should return NULL from your new method.  This is what we do where appropriate.  And, yes, you should also clean-up anything you&#8217;ve alloc&#8217;d from the heap in the process.</p>
<p>Cheers,<br />
   Tim</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

