473,388 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Memory usage of foreach

I read somewhere that 'foreach' iterates over a 'copy' of the array, whereas
doing something like:

while (list($key, $value) = each($myarray))

iterates over the original array. Up til now, I've been using the 'foreach'
method.

If this is true then I'm concerned about memory usage as some of the arrays
I'm working on can grow fairly large.

Is it possible to check memory usage of your php program?

I may be converting code over to the list() method. What are the caveats of
doing this?

Daniel Klein
Apr 8 '08 #1
2 2645
..oO(Daniel Klein)
>I read somewhere that 'foreach' iterates over a 'copy' of the array, whereas
doing something like:

while (list($key, $value) = each($myarray))

iterates over the original array. Up til now, I've been using the 'foreach'
method.

If this is true then I'm concerned about memory usage as some of the arrays
I'm working on can grow fairly large.

Is it possible to check memory usage of your php program?
http://php.net/memory_get_usage
>I may be converting code over to the list() method. What are the caveats of
doing this?
Do you run into performance problems?

Google "premature optimization" and use a profiler to find the real
bottlenecks in your code.

Micha
Apr 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James B. | last post by:
I have written a perl script to parse some large flat-text logs. The logs are bzipped and come in through a pipe to STDIN. The script then performs some regular expressions to the incoming data...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
25
by: Zeng | last post by:
I finally narrowed down my code to this situation, quite a few (not all) of my CMyClass objects got hold up after each run of this function via the simple webpage that shows NumberEd editbox. My...
8
by: nautonnier | last post by:
I know my problem has been discussed ad nauseum but I still don't get it so please bear with me. I have written a service which performs some work against a database once a day (usually in the...
1
by: Frank Rizzo | last post by:
I have an application (windows service) that in the beginning reads data rapidly into a collection of large object trees. Each object tree in the collection is about 100mb and typically there are...
2
jlm699
by: jlm699 | last post by:
Greetings all, I'm using a PHP-based web page to access an SQL database containing logs which has grown quite large over time. A few weeks ago I recieved the following error: "Fatal error: Allowed...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
8
by: SageX | last post by:
Hello Gentlemen.. I have a program that is calculating all possible permutations of objects within an object. The code looks very much like... foreach (item as currentItem in Items) { ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.