ObjFW  Check-in [def4850926]

Overview
Comment:Save 16 bytes per object on 64 bit systems with a 16 byte alignment.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: def4850926bfcf2f37470b1dba387cb0d9d946b4faaf52c976b10ae4a6b8b134
User & Date: js on 2011-06-10 18:19:36
Other Links: manifest | tags
Context
2011-06-11
00:24
Add OFFloatVector. check-in: d94b9059f2 user: js tags: trunk
2011-06-10
18:19
Save 16 bytes per object on 64 bit systems with a 16 byte alignment. check-in: def4850926 user: js tags: trunk
2011-06-07
14:10
Small changes to OF_SETTER/OF_GETTER. check-in: 9e2ea02a08 user: js tags: trunk
Changes

Modified src/OFObject.m from [05402e39fd] to [ace848aef2].

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# define class_getName class_get_class_name
# define class_getSuperclass class_get_super_class
# define sel_registerName sel_get_uid
#endif

struct pre_ivar {
	void	      **memoryChunks;
	size_t	      memoryChunksSize;
	int32_t	      retainCount;
#if !defined(OF_ATOMIC_OPS)
	of_spinlock_t retainCountSpinlock;
#endif
};

/* Hopefully no arch needs more than 16 bytes padding */







|







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# define class_getName class_get_class_name
# define class_getSuperclass class_get_super_class
# define sel_registerName sel_get_uid
#endif

struct pre_ivar {
	void	      **memoryChunks;
	unsigned int  memoryChunksSize;
	int32_t	      retainCount;
#if !defined(OF_ATOMIC_OPS)
	of_spinlock_t retainCountSpinlock;
#endif
};

/* Hopefully no arch needs more than 16 bytes padding */
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
	/* Classes containing data should reimplement this! */
	return [OFString stringWithFormat: @"<%@: %p>", [self className], self];
}

- (void)addMemoryToPool: (void*)pointer
{
	void **memoryChunks;
	size_t memoryChunksSize;

	memoryChunksSize = PRE_IVAR->memoryChunksSize + 1;

	if (SIZE_MAX - PRE_IVAR->memoryChunksSize < 1 ||
	    memoryChunksSize > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((memoryChunks = realloc(PRE_IVAR->memoryChunks,
	    memoryChunksSize * sizeof(void*))) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: memoryChunksSize];

	PRE_IVAR->memoryChunks = memoryChunks;
	PRE_IVAR->memoryChunks[PRE_IVAR->memoryChunksSize] = pointer;
	PRE_IVAR->memoryChunksSize = memoryChunksSize;
}

- (void*)allocMemoryWithSize: (size_t)size
{
	void *pointer, **memoryChunks;
	size_t memoryChunksSize;

	if (size == 0)
		return NULL;

	memoryChunksSize = PRE_IVAR->memoryChunksSize + 1;

	if (SIZE_MAX - PRE_IVAR->memoryChunksSize == 0 ||
	    memoryChunksSize > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((pointer = malloc(size)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: size];

	if ((memoryChunks = realloc(PRE_IVAR->memoryChunks,







|



|
|















|






|
|







576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
	/* Classes containing data should reimplement this! */
	return [OFString stringWithFormat: @"<%@: %p>", [self className], self];
}

- (void)addMemoryToPool: (void*)pointer
{
	void **memoryChunks;
	unsigned int memoryChunksSize;

	memoryChunksSize = PRE_IVAR->memoryChunksSize + 1;

	if (UINT_MAX - PRE_IVAR->memoryChunksSize < 1 ||
	    memoryChunksSize > UINT_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((memoryChunks = realloc(PRE_IVAR->memoryChunks,
	    memoryChunksSize * sizeof(void*))) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: memoryChunksSize];

	PRE_IVAR->memoryChunks = memoryChunks;
	PRE_IVAR->memoryChunks[PRE_IVAR->memoryChunksSize] = pointer;
	PRE_IVAR->memoryChunksSize = memoryChunksSize;
}

- (void*)allocMemoryWithSize: (size_t)size
{
	void *pointer, **memoryChunks;
	unsigned int memoryChunksSize;

	if (size == 0)
		return NULL;

	memoryChunksSize = PRE_IVAR->memoryChunksSize + 1;

	if (UINT_MAX - PRE_IVAR->memoryChunksSize == 0 ||
	    memoryChunksSize > UINT_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((pointer = malloc(size)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: size];

	if ((memoryChunks = realloc(PRE_IVAR->memoryChunks,
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
	return [self resizeMemory: pointer
			   toSize: nItems * size];
}

- (void)freeMemory: (void*)pointer
{
	void **iter, *last, **memoryChunks;
	size_t i, memoryChunksSize;

	if (pointer == NULL)
		return;

	iter = PRE_IVAR->memoryChunks + PRE_IVAR->memoryChunksSize;
	i = PRE_IVAR->memoryChunksSize;








|







693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
	return [self resizeMemory: pointer
			   toSize: nItems * size];
}

- (void)freeMemory: (void*)pointer
{
	void **iter, *last, **memoryChunks;
	unsigned int i, memoryChunksSize;

	if (pointer == NULL)
		return;

	iter = PRE_IVAR->memoryChunks + PRE_IVAR->memoryChunksSize;
	i = PRE_IVAR->memoryChunksSize;