Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does functional programming take up more memory?

Warning! possibly a very dumb question

Does functional programming eat up more memory than procedural programming? I mean ... if your objects(data structures whatever) are all imutable. Don't you end up having more object in the memory at a given time.

Doesn't this eat up more memory?

like image 852
Para Avatar asked Dec 23 '10 20:12

Para


People also ask

Is functional programming less efficient?

Efficiency issuesFunctional programming languages are typically less efficient in their use of CPU and memory than imperative languages such as C and Pascal. This is related to the fact that some mutable data structures like arrays have a very straightforward implementation using present hardware.

Do functional programs run faster?

It's faster because it's easier to write your code in a way that's easier to compile faster. You won't necessarily get a speed difference by switching languages, but if you had started with a functional language, you could have probably done the multithreading with a lot less programmer effort.

Is functional programming always slow?

Functional languages will seem slower because you'll only ever see benchmarks comparing code that is easy enough to write well in C and you'll never see benchmarks comparing meatier tasks where functional languages start to excel.


1 Answers

It depends on what you're doing. With functional programming you don't have to create defensive copies, so for certain problems it can end up using less memory.

Many functional programming languages also have good support for laziness, which can further reduce memory usage as you don't create objects until you actually use them. This is arguably something that's only correlated with functional programming rather than a direct cause, however.

like image 137
Laurence Gonsalves Avatar answered Sep 19 '22 18:09

Laurence Gonsalves