mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Rewrite of NSData from Richard Frith-Macdonald <richard@brainstorm.co.uk>
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2459 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7b704b0ec4
commit
f88a65db7e
32 changed files with 1576 additions and 2603 deletions
|
@ -1,11 +1,14 @@
|
|||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
id a;
|
||||
id d;
|
||||
id o;
|
||||
id pool;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
@ -14,7 +17,76 @@ main()
|
|||
if (d == nil)
|
||||
printf("Unable to map file");
|
||||
printf("Mapped %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
d = [NSData dataWithContentsOfFile:@"nsdata.m"];
|
||||
if (d == nil)
|
||||
printf("Unable to read file");
|
||||
printf("Read %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
d = [NSData dataWithSharedBytes: [d bytes] length: [d length]];
|
||||
if (d == nil)
|
||||
printf("Unable to make shared data");
|
||||
printf("Shared data of %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
d = [NSMutableData dataWithSharedBytes: [d bytes] length: [d length]];
|
||||
if (d == nil)
|
||||
printf("Unable to make mutable shared data");
|
||||
printf("Mutable shared data of %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
[d appendBytes: "Hello world" length: 11];
|
||||
printf("Extended by 11 bytes to %d bytes\n", [d length]);
|
||||
|
||||
d = [NSMutableData dataWithShmID: [d shmID] length: [d length]];
|
||||
if (d == nil)
|
||||
printf("Unable to make mutable data with old ID\n");
|
||||
printf("data with shmID gives data length %d\n", [d length]);
|
||||
|
||||
a = [[NSArchiver new] autorelease];
|
||||
[a encodeRootObject: d];
|
||||
printf("Encoded data into archive\n");
|
||||
a = [[NSUnarchiver alloc] initForReadingWithData: [a archiverData]];
|
||||
o = [a decodeObject];
|
||||
printf("Decoded data from archive - length %d\n", [o length]);
|
||||
[a release];
|
||||
[o release];
|
||||
|
||||
[d setCapacity: 2000000];
|
||||
printf("Set capacity of shared memory item to %d\n", [d capacity]);
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include <gnustep/base/Connection.h>
|
||||
#include <gnustep/base/Array.h>
|
||||
|
||||
typedef struct _small_struct {
|
||||
typedef struct _small_struct {
|
||||
unsigned char z;
|
||||
} small_struct;
|
||||
|
||||
|
||||
typedef struct _foo {
|
||||
int i;
|
||||
char *s;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue