Skip to content

Instantly share code, notes, and snippets.

View SeaHub's full-sized avatar

Seahub SeaHub

View GitHub Profile
@SeaHub
SeaHub / Dealloc.m
Last active March 4, 2017 07:04
Dealloc realization in GNUStep Foundation
/**
* Deallocates the receiver by calling NSDeallocateObject() with self
* as the argument.<br />
* <p>
* You should normally call the superclass implementation of this method
* when you override it in a subclass, or the memory occupied by your
* object will not be released.
* </p>
* <p>
* <code>NSObject</code>'s implementation of this method
@SeaHub
SeaHub / Release.m
Last active March 4, 2017 06:59
Release realization in GNUStep Foundation
/**
* Decrements the retain count for the receiver if greater than zero,
* otherwise calls the dealloc method instead.<br />
* The default implementation calls the NSDecrementExtraRefCountWasZero()
* function to test the extra reference count for the receiver (and
* decrement it if non-zero) - if the extra reference count is zero then
* the retain count is one, and the dealloc method is called.<br />
* In GNUstep, the [NSObject+enableDoubleReleaseCheck:] method may be used
* to turn on checking for ratain/release errors in this method.
*/
@SeaHub
SeaHub / Retain.m
Last active March 4, 2017 06:59
Retain realization in GNUStep Foundation
/**
* Increments the reference count and returns the receiver.<br />
* The default implementation does this by calling NSIncrementExtraRefCount()
*/
- (id)retain {
#if (GS_WITH_GC == 0)
NSIncrementExtraRefCount(self);
#endif
return self;
}
@SeaHub
SeaHub / Alloc.m
Last active March 4, 2017 07:00
Alloc realization in GNUStep Foundation
#define AADD(c, o) GSDebugAllocationAdd(c, o)
static SEL cxx_construct, cxx_destruct;
/**
* Calls the C++ constructors for this object, starting with the ones declared
* in aClass. The compiler generates two methods on Objective-C++ classes that
* static instances of C++ classes as ivars. These are -.cxx_construct and
* -.cxx_destruct. The -.cxx_construct methods must be called in order from
* the root class to all subclasses, to ensure that subclass ivars are
* initialised after superclass ones. This must be done in reverse for
@SeaHub
SeaHub / QuickSort.cpp
Last active March 25, 2017 07:25
QuickSort(C++)
//
// QuickSort
//
// Created by SeaHub on 2017/3/3.
// Copyright © 2017年 @Seahub. All rights reserved.
//
#include <iostream>
#include <vector>
using namespace std;
@SeaHub
SeaHub / Singleton.m
Created March 3, 2017 01:46
A Good Objc Singleton
//
// Singleton
//
// Created by SeaHub on 2017/3/2.
// Copyright © 2017年 @Seahub All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Singleton : NSObject <NSCopying, NSMutableCopying>