ObjFW  Diff

Differences From Artifact [80b6b20e53]:

To Artifact [20042a6dbe]:

  • File src/OFAutoreleasePool.h — part of check-in [f92e1c77a0] at 2010-07-08 09:20:54 on branch trunk — Optimize OFAutoreleasePool.

    It always allocates memory for 16 objects now. releaseObjects does not
    free the memory allocated to store objects so that the same number of
    objects can be stored in the autorelease pool again without the need to
    allocate memory. This will give loops creating lots of objects a huge
    performance boost. (user: js, size: 2164) [annotate] [blame] [check-ins using]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import "OFObject.h"

@class OFMutableArray;

/**
 * \brief A pool that keeps track of objects to release.
 *
 * The OFAutoreleasePool class is a class that keeps track of objects that will
 * be released when the autorelease pool is released.
 *
 * Every thread has its own stack of autorelease pools.
 */
@interface OFAutoreleasePool: OFObject
{
	OFMutableArray *objects;
	OFAutoreleasePool *next, *prev;


}

/**
 * Adds an object to the autorelease pool at the top of the thread-specific
 * stack.
 *
 * \param obj The object to add to the autorelease pool













<
<










<

>
>







1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import "OFObject.h"



/**
 * \brief A pool that keeps track of objects to release.
 *
 * The OFAutoreleasePool class is a class that keeps track of objects that will
 * be released when the autorelease pool is released.
 *
 * Every thread has its own stack of autorelease pools.
 */
@interface OFAutoreleasePool: OFObject
{

	OFAutoreleasePool *next, *prev;
	id *objects;
	size_t count, size;
}

/**
 * Adds an object to the autorelease pool at the top of the thread-specific
 * stack.
 *
 * \param obj The object to add to the autorelease pool
42
43
44
45
46
47
48







49
50
51
52
53
54
55
 *
 * \param obj The object to add to the autorelease pool
 */
- (void)addObject: (OFObject*)obj;

/**
 * Releases all objects in the autorelease pool.







 *
 * If a garbage collector is added in the future, it will tell the GC that now
 * is a good time to clean up, as this is often used after a lot of objects
 * have been added to the pool that should be released before the next iteration
 * of a loop, which adds objects again. Thus, it is usually a clean up call.
 */
- (void)releaseObjects;







>
>
>
>
>
>
>







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 *
 * \param obj The object to add to the autorelease pool
 */
- (void)addObject: (OFObject*)obj;

/**
 * Releases all objects in the autorelease pool.
 *
 * This does not free the memory allocated to store pointers to the objects in
 * the pool, so reusing the pool does not allocate any memory until the previous
 * number of objects is exceeded. It behaves this way to optimize loops that
 * always work with the same or similar number of objects and call relaseObjects
 * at the end of the loop, which is propably the most common case for
 * releaseObjects.
 *
 * If a garbage collector is added in the future, it will tell the GC that now
 * is a good time to clean up, as this is often used after a lot of objects
 * have been added to the pool that should be released before the next iteration
 * of a loop, which adds objects again. Thus, it is usually a clean up call.
 */
- (void)releaseObjects;