| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2010-11-03 16:53 UTC] lifinsky at yandex dot ru
 Description:
------------
I test linkedList performance and memory usage on Windows Vista Premium with PHP 5.3.3. When list length > 34860 I have server fatal Error ( Segmentation fault) and my fast-cgi script closed. I try test on Linux (PHP 5.2.6) but have some error if length ~ 32735. This error is not related with memory limit.
Test script:
---------------
class LinkedList { 
	private $_length = 0;
	private $_head;
	private $_tail;
	public function add($data) {
		$node = (object) array('data' => $data, 'next' => null);
		if ($this->_length == 0) {
			$this->_head = $node;
			$this->_tail = $node;
		} else {
			$this->_tail->next = $node;
			$this->_tail = $node;
		}
		$this->_length++;
	}
}
$a = new LinkedList();
$startMemory = memory_get_usage();
$start = microtime(true);
for ($i = 1; $i <= 34860; $i++) {
	$a->add($i);
}
$endMemory = memory_get_usage();
$end = microtime(true);
print(($end - $start) . '<br />');
print((int) (($endMemory - $startMemory) / 1024) . '<br />');
Expected result:
----------------
If length = 34860 I got 
0.12323784828186
11276
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 04:00:01 2025 UTC | 
Without this line we will not have LinkedList Example in JSON Format: { data: 1 next: { data: 2 next: { data: 3 next: ... } } }