diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-11-23 23:08:55 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-11-23 23:08:55 +0000 |
commit | 49c13abfb7c2529d9292f4994dc889ef97b311b3 (patch) | |
tree | c58dfc4024c8829dc7bf9e5c2a0104fd333a5c70 | |
parent | e648d4ed83173f0af1bd16af804d1f605586c703 (diff) | |
download | ATCD-49c13abfb7c2529d9292f4994dc889ef97b311b3.tar.gz |
ChangeLogTag:Tue Nov 23 12:47:39 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
-rw-r--r-- | ChangeLog-99b | 9 | ||||
-rw-r--r-- | ace/Malloc.h | 23 | ||||
-rw-r--r-- | tests/Malloc_Test.cpp | 19 | ||||
-rw-r--r-- | tests/Malloc_Test.h | 1 |
4 files changed, 38 insertions, 14 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b index 46cf0cad739..d78ec72949c 100644 --- a/ChangeLog-99b +++ b/ChangeLog-99b @@ -1,3 +1,12 @@ +Tue Nov 23 12:47:39 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * tests/Malloc_Test: Updated the Malloc_Test so that it'll + allocate and test doubles to make sure they work correctly. + + * ace/Malloc.h: Modified the alignment logic to make things + work properly for datatypes like doubles. Thanks to Alexander + Belopolsky <belopolsky@my-deja.com> for working this out. + Tue Nov 23 12:02:53 1999 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> * ace/OS.i: Moved the inline methods for sec()/usec()/msec() so diff --git a/ace/Malloc.h b/ace/Malloc.h index 567e1a5007c..4a0c99b3e63 100644 --- a/ace/Malloc.h +++ b/ace/Malloc.h @@ -78,6 +78,13 @@ struct ACE_Export ACE_Malloc_Stats #define ACE_MALLOC_PADDING 1 #endif /* ACE_MALLOC_PADDING */ +#if !defined (ACE_MALLOC_ALIGN) +// Align to an address that's a multiple of a double. Notice the +// casting to int for <sizeof> since otherwise unsigned int arithmetic +// is used and some awful things may happen. +#define ACE_MALLOC_ALIGN (int (sizeof (double))) +#endif /* ACE_MALLOC_ALIGN */ + #if defined (ACE_HAS_POSITION_INDEPENDENT_MALLOC) #define ACE_MALLOC_HEADER_PTR ACE_Based_Pointer<ACE_Malloc_Header> #define ACE_NAME_NODE_PTR ACE_Based_Pointer<ACE_Name_Node> @@ -105,7 +112,7 @@ public: #if (ACE_MALLOC_PADDING > 1) #define ACE_MALLOC_PADDING_SIZE ((ACE_MALLOC_PADDING - \ - (sizeof (ACE_Malloc_Header)) / sizeof (long))) + (sizeof (ACE_Malloc_Header)) / ACE_MALLOC_ALIGN)) long padding_[ACE_MALLOC_PADDING_SIZE < 1 : ACE_MALLOC_PADDING_SIZE]; #endif /* ACE_MALLOC_PADDING > 0 */ @@ -193,23 +200,21 @@ public: #if defined (ACE_HAS_MALLOC_STATS) // Keep statistics about ACE_Malloc state and performance. ACE_Malloc_Stats malloc_stats_; -#define ACE_CONTROL_BLOCK_SIZE ((int)(sizeof (ACE_Name_Node *) \ +#define ACE_CONTROL_BLOCK_SIZE ((int)(sizeof (ACE_NAME_NODE_PTR) \ + sizeof (ACE_Malloc_Header *) \ + MAXNAMELEN \ + sizeof (ACE_Malloc_Stats))) #else -#define ACE_CONTROL_BLOCK_SIZE ((int)(sizeof (ACE_Name_Node *) \ +#define ACE_CONTROL_BLOCK_SIZE ((int)(sizeof (ACE_NAME_NODE_PTR) \ + sizeof (ACE_Malloc_Header *) \ + MAXNAMELEN)) #endif /* ACE_HAS_MALLOC_STATS */ -// Notice the casting to int for <sizeof> otherwise unsigned int -// arithmetic is used and some awful things may happen. -#define ACE_CONTROL_BLOCK_ALIGN_LONGS ((ACE_CONTROL_BLOCK_SIZE % ACE_MALLOC_PADDING != 0 \ - ? ACE_MALLOC_PADDING - (ACE_CONTROL_BLOCK_SIZE) \ - : ACE_MALLOC_PADDING) / int (sizeof (long))) +#define ACE_CONTROL_BLOCK_ALIGN ((ACE_CONTROL_BLOCK_SIZE % ACE_MALLOC_ALIGN != 0 \ + ? ACE_MALLOC_ALIGN - (ACE_CONTROL_BLOCK_SIZE) \ + : ACE_MALLOC_ALIGN) / ACE_MALLOC_ALIGN) - long align_[ACE_CONTROL_BLOCK_ALIGN_LONGS < 1 ? 1 : ACE_CONTROL_BLOCK_ALIGN_LONGS]; + long align_[ACE_CONTROL_BLOCK_ALIGN < 1 ? 1 : ACE_CONTROL_BLOCK_ALIGN]; // Force alignment. ACE_Malloc_Header base_; diff --git a/tests/Malloc_Test.cpp b/tests/Malloc_Test.cpp index ac0c2cc3b01..1d658d160ad 100644 --- a/tests/Malloc_Test.cpp +++ b/tests/Malloc_Test.cpp @@ -63,6 +63,14 @@ myallocator (const void *base_addr = 0) static Test_Data * initialize (MALLOC *allocator) { + double *temp = 0; + ACE_ALLOCATOR_RETURN (temp, + (double *) allocator->malloc (sizeof (double)), + 0); + // Make sure that doubles work! + *temp = 5.0; + allocator->free (temp); + void *ptr; ACE_ALLOCATOR_RETURN (ptr, allocator->malloc (sizeof (Test_Data)), @@ -72,6 +80,7 @@ initialize (MALLOC *allocator) data1->i1_ = 111; data1->i2_ = 222; data1->i3_ = 333; + data1->d1_ = 87.5; void *gap = 0; ACE_ALLOCATOR_RETURN (gap, @@ -79,19 +88,18 @@ initialize (MALLOC *allocator) 0); allocator->free (gap); + ACE_ALLOCATOR_RETURN (ptr, allocator->malloc (sizeof (Test_Data)), 0); Test_Data *data2 = new (ptr) Test_Data; data1->next_ = 0; - data1->i1_ = 111; - data1->i2_ = 222; - data1->i3_ = 333; data2->next_ = data1; data2->i1_ = -111; data2->i2_ = -222; data2->i3_ = -333; + data2->d1_ = 77.34; // Test in shared memory using long (array/pointer) ACE_ALLOCATOR_RETURN (ptr, @@ -144,11 +152,12 @@ print (const char *process_name, for (Test_Data *t = data; t != 0; t = t->next_) { ACE_DEBUG ((LM_DEBUG, - ASYS_TEXT ("<<<< (%P) %s\ni1_ = %d, i2_ = %d, i3_ = %d\n"), + ASYS_TEXT ("<<<< (%P) %s\ni1_ = %d, i2_ = %d, i3_ = %d, d1_ = %f\n"), process_name, t->i1_, t->i2_, - t->i3_)); + t->i3_, + t->d1_)); ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("*t->bpl_ = %d, t->long_test_->array_[0] = ") ASYS_TEXT ("%d\n>>>>\n"), diff --git a/tests/Malloc_Test.h b/tests/Malloc_Test.h index 8cb99e0c7e0..8fda7368ee4 100644 --- a/tests/Malloc_Test.h +++ b/tests/Malloc_Test.h @@ -36,6 +36,7 @@ struct Test_Data int i1_; int i2_; int i3_; + double d1_; ACE_Based_Pointer<Test_Data> next_; ACE_Based_Pointer<Long_Test> long_test_; }; |