Index: Include/Classes/System/Collections/ArrayList.ab
===================================================================
--- Include/Classes/System/Collections/ArrayList.ab	(revision 188)
+++ Include/Classes/System/Collections/ArrayList.ab	(revision 195)
@@ -5,18 +5,62 @@
 Class ArrayList
 	Inherits IList /*, ICollection, IEnumerable, ICloneable*/
+
+	pObject As *Object
+	size As Long
+	capacity As Long
+
+	Sub Init( size As Long )
+		If size < 0 Then
+			' Error
+			debug
+		End If
+
+		This.size = size
+		This.capacity = size
+
+		pObject = GC_malloc( SizeOf(*Object) * size + 1 )
+		If pObject = 0 Then
+			' OutOfMemoryException
+			Debug
+		End If
+	End Sub
+
+	Sub Realloc( size As Long )
+		If size > capacity Then
+			' miss!
+			Debug
+		End If
+
+		pObject = realloc( pObject, SizeOf(*Object) * size + 1  )
+		If pObject = 0 Then
+			' OutOfMemoryException
+			Debug
+		End If
+	End Sub
+
+	Sub SetLeastCapacity( capacity As Long )
+		If This.capacity < capacity Then
+			This.capacity = capacity 
+			Realloc( capacity )
+		End If
+	End Sub
+
 Public
-	' --------------------------------
+
+	'----------------------------------------------------------------
 	' Properties
+	'----------------------------------------------------------------
+
 	/*Const*/ Virtual Function Capacity() As Long
-		Return data.Capacity
+		Return capacity
 	End Function
 
 	Virtual Sub Capacity(c As Long)
-		If c <> data.Capacity Then
-			If c < data.Size Then
+		If c <> capacity Then
+			If c < size Then
 				'Throw ArgumentOutOfRangeException
 				Debug
 			Else
-				reallocBuffer(c)
+				Realloc(c)
 			End If
 		End If
@@ -24,5 +68,5 @@
 
 	/*Const*/ /*Override*/ Virtual Function Count() As Long
-		Return data.Size
+		Return size
 	End Function
 
@@ -41,7 +85,7 @@
 
 	' Operators
-	/*Const*/ /*Override*/ Virtual Function Operator [](i As Long) As *Object
-		If 0 <= i And i < data.Size Then
-			Return data.Elm[i]
+	/*Const*/ /*Override*/ Virtual Function Operator [](index As Long) As Object
+		If 0 <= index And index < size Then
+			Return pObject[index]
 		Else
 			'Throw OutOfRangeException?
@@ -50,7 +94,7 @@
 	End Function
 	
-	/*Override*/ Virtual Sub Operator []=(i As Long, x As *Object)
-		If 0 <= i And i < data.Size Then
-			data.Elm[i] = 0
+	/*Override*/ Virtual Sub Operator []=(index As Long, object As Object)
+		If 0 <= index And index < size Then
+			pObject[i] = object
 		Else
 			'Throw OutOfRangeException?
@@ -59,9 +103,13 @@
 	End Sub
 
-	' --------------------------------
+
+
+	'----------------------------------------------------------------
 	' Methods
+	'----------------------------------------------------------------
+
 	'   Constractors
 	Sub ArrayList()
-		data.Init(16)
+		Init( 0 )
 	End Sub
 /*
@@ -72,5 +120,5 @@
 */
 	Sub ArrayList(c As Long)
-		data.Init(c)
+		Init( c )
 	End Sub
 
@@ -81,16 +129,9 @@
 '	Sub Operator =(ByRef a As ArrayList)
 
-	/*Override*/ Virtual Function Add(x As *Object) As Long
-		setLeastCapacity(data.Size + 1)
-		data.Elm[data.Size] = x
-		Add = data.Size
-		data.Size++
-	End Function
-
-	/*Override*/ Virtual Function Add(x As Object) As Long
-		setLeastCapacity(data.Size + 1)
-		data.Elm[data.Size] = VarPtr(x)
-		Add = data.Size
-		data.Size++
+	/*Override*/ Virtual Function Add( object As Object ) As Long
+		SetLeastCapacity( size + 1 )
+		pObject[size] = object
+		size++
+		Return size - 1
 	End Function
 
@@ -112,18 +153,16 @@
 
 	/*Override*/ Virtual Sub Clear()
-		data.Size = 0
-	End Sub
-
-	Virtual Function Clone() As *ArrayList
-		Dim p As *ArrayList
-		p = New ArrayList(data.Size)
-		p->data.Size = data.Size
-		memcpy(p->data.Elm, This.data.Elm, SizeOf (*Object) * data.Size)
-		Return p
+		size = 0
+	End Sub
+
+	Virtual Function Clone() As ArrayList
+		Dim arrayList = New ArrayList( size )
+		memcpy( arrayList.pObject, This.pObject, SizeOf(*Object) * size )
+		Return arrayList
 	End Function
 
 	/*Const*/ /*Override*/ /*Virtual Function Contains(x As *Object) As Boolean
 		Dim i As Long
-		For i = 0 To ELM(data.Size)
+		For i = 0 To ELM(size)
 			If x->Equals(data.Elm[i]) Then
 				Return True
@@ -145,27 +184,28 @@
 	End Function
 
-	/*Const*/ Override Function IndexOf(x As *Object) As Long
-		Return IndexOf(x, 0, data.Size)
-	End Function
-
-	/*Const*/ Virtual Function IndexOf(x As *Object, startIndex As Long) As Long
-		Return IndexOf(x, startIndex, data.Size - startIndex)
-	End Function
-
-	/*Const*/ Virtual Function IndexOf(x As *Object, startIndex As Long, count As Long) As Long
+	/*Const*/ Override Function IndexOf(object As Object) As Long
+		Return IndexOf(object, 0, size)
+	End Function
+
+	/*Const*/ Virtual Function IndexOf(object As Object, startIndex As Long) As Long
+		Return IndexOf(object, startIndex, size - startIndex)
+	End Function
+
+	/*Const*/ Virtual Function IndexOf(object As Object, startIndex As Long, count As Long) As Long
 		Dim i As Long
-		Dim last = Math.Min(startIndex + count - 1, data.Size)
+		Dim last = Math.Min(startIndex + count - 1, size)
 		For i = startIndex To last
-			If x->Equals(ByVal data.Elm[i]) Then
+			If object.Equals( pObject[i] ) Then
 				Return i
 			End If
 		Next
-	End Function
-
-	Override Sub Insert(i As Long, x As *Object)
-		setLeastCapacity(data.Size + 1)
-		memmove(VarPtr(data.Elm[i + 1]), VarPtr(data.Elm[i]), SizeOf (*Object) * (data.Size - i))
-		data.Elm[i] = x
-		data.Size++
+		Return -1
+	End Function
+
+	Override Sub Insert(i As Long, object As Object)
+		SetLeastCapacity(size + 1)
+		memmove(VarPtr(pObject[i + 1]), VarPtr(pObject[i]), SizeOf (*Object) * (size - i))
+		pObject[i] = object
+		size++
 	End Sub
 
@@ -174,20 +214,21 @@
 	End Sub
 
-	/*Const*/ Virtual Function LastIndexOf(x As *Object) As Long
-		LastIndexOf(x, 0, data.Size)
-	End Function
-
-	/*Const*/ Virtual Function LastIndexOf(x As *Object, startIndex As Long) As Long
-		Return LastIndexOf(x, startIndex, data.Size - startIndex)
-	End Function
-
-	/*Const*/ Virtual Function LastIndexOf(x As *Object, startIndex As Long, count As Long) As Long
-		' TODO: 実装
-	End Function
-
-	Override Sub Remove(x As *Object)
-		Dim i = IndexOf(x)
+	/*Const*/ Virtual Function LastIndexOf(object As Object) As Long
+		LastIndexOf(object, 0, size)
+	End Function
+
+	/*Const*/ Virtual Function LastIndexOf(object As Object, startIndex As Long) As Long
+		Return LastIndexOf(object, startIndex, size - startIndex)
+	End Function
+
+	/*Const*/ Virtual Function LastIndexOf(object As Object, startIndex As Long, count As Long) As Long
+		' TODO: 実装
+	End Function
+
+	Override Sub Remove(object As Object)
+		Dim i = IndexOf(object)
 		If i > 0 Then
 			RemoveAt(i)
+			size--
 		End If
 	End Sub
@@ -195,13 +236,15 @@
 	Override Sub RemoveAt(i As Long)
 		RemoveRange(i, 1)
+		size--
 	End Sub
 	
 	Virtual Sub RemoveRange(i As Long, count As Long)
 		Dim removeLastPos = i + count
-		memmove(VarPtr(data.Elm[i]), VarPtr(data.Elm[removeLastPos]), SizeOf (*Object) * (data.Size - removeLastPos))
+		memmove(VarPtr(pObject[i]), VarPtr(pObject[removeLastPos]), SizeOf(*Object) * (size - removeLastPos))
+		size -= count
 	End Sub
 
 	Virtual Sub Reverse()
-		Reverse(0, data.Size)
+		Reverse(0, size)
 	End Sub
 
@@ -219,5 +262,5 @@
 
 	Virtual Sub Sort(ByRef c As IComparer)
-		Sort(0, data.Size, c)
+		Sort(0, size, c)
 	End Sub
 
@@ -228,5 +271,5 @@
 	' ToArray
 	Virtual Sub TrimToSize()
-		reallocBuffer(data.Size)
+		Realloc(size)
 	End Sub
 
@@ -273,21 +316,7 @@
 	End Function
 
-Private
-	Sub setLeastCapacity(c As Long)
-		If data.Capacity < c Then
-			reallocBuffer(c)
-		End If
-	End Sub
-
-	Sub reallocBuffer(c As Long)
-		Dim newBuf As ArrayList_Element(c)
-		newBuf.Size = data.Size
-		memcpy(newBuf.Elm, data.Elm, SizeOf (*Object) * newBuf.Size)
-		newBuf.Swap(data)
-	End Sub
-
-	data As ArrayList_Element
 End Class
 
+/*
 Class ArrayList_Element
 Public
@@ -335,2 +364,3 @@
 	Capacity As Long
 End Class
+*/
