Are pointers important for scientific research?

In summary: I think the most important thing about pointers is that they give you the ability to manipulate memory addresses programmatically, which can be very useful in some scenarios. In languages like C and C++, pointers are essential for working with certain data structures like linked lists and trees. They also allow for more efficient memory management, as you can allocate and deallocate memory dynamically at runtime.In summary, pointers are widely used in scientific programming, particularly in C and C++. They provide a way to manage memory efficiently and are essential for working with data structures like linked lists and trees. While there may be debates about the use of pointers in these languages, they still play a crucial role in optimizing performance and managing memory in scientific programs.
  • #1
Simfish
Gold Member
823
2
A lot of scientific programs are CPU-intensive, so speed is important. Pointers have to do with memory management, which I presume is important since there are often so many array values that memory management becomes important. yet, I don't see it used very often. Are they used very often?
 
Technology news on Phys.org
  • #2
C/C++. Which seems to be one of the most popular languages for scientific computing.
 
  • #3
I thought that was FORTRAN for numeric intensive computing, Prolog or Lisp for artificial intelligence / language parsing, ADA for space shuttle things and other things that can't go wrong and what-ever ML-spawn for simulations and physics.

But C's probably also decent enough for the first, apparently FORTRAN has better libraries or something, I never got why they all use FORTRAN for that why C is just as good, if not better.

Maybe COBOL works well too.

But to answer your quaestion, pointers are essential and people use pointers implicitly more than they realize. But it depends for what, pointers don't magically 'speed up' things, they just help you program things that would be really cumbersome to program without.

Edit: Also, an array is a pointer, an array of integers is a pointer of type integer, so yeah, if you use array you use pointers.
 
  • #4
No religious arguments on the whether C/C++ is a good or bad language, or on its merits as a language for scientific programming.

In C and in C++ when you pass a primitive array (e.g. double array[3]) to a function you are passing a pointer. C, for good or for bad, pushes things to pointers rather quickly. C++ uses references as well as pointers. References are essentially pointers, but with some of the loosy-goosy nature of raw pointers in C.

C++ offers containers in the Standard Template Library that go well beyond the simple pointers and references. Sometimes these container objects can be very useful, but sometimes they are quite hoggish of CPU and memory.

As far as whether pointers and their more advanced kin are used in scientific programming: Yes. All the time.
 
  • #5
Pointers are used a lot in C and C++, particular in functions that have "call by reference" parameters,. Pointers don't necessarily have to do with memory management, as such, but can be used to provide access to a chunk of data rather than having to deal with the individual items of data. For example, a function can be passed the address of a block of memory, rather than the memory block itself.

Certain data structures, such as linked lists, queues, and such, are often implemented so that the individual components that make up the list or queue have pointers to the next and/or preceding structure in the list.

Kajahtava said:
Assembly is fast, assembly doesn't have pointers.
Assembly languages might not have pointers, per se, but the ones I'm familiar with, such as x86 and M68000, certainly have the concept of pointers, in which the contents of memory or a register are considered to be an address an memory, rather than just a plain value.
 
  • #6
Kajahtava said:
I thought that was FORTRAN for numeric intensive computing,
Less and less. Fortran has been losing ground for quite some time. BTW, it's Fortran now, not FORTRAN. Regarding the question raised in the OP, FORTRAN had references very early on, and Fortran 90 has pointers.

ADA for space shuttle things and other things that can't go wrong
Ada is/was a failed experiment. The Shuttle predates Ada; it is programmed in HAL/S. The ISS is programmed in Ada. None since that I know of. DoD removed the Ada mandate in 1997. Most of NASA's new spacecraft are programmed in C++.

Raw pointers (but not references) are pretty much verboten in real-time high-reliability applications such as flight software. Then again, so is almost all of the STL.
 
  • #7
Seems like a very odd question, asking whether a particular programming-language construct is important to scientific research or not.

I know a lot of stuff I do is still written in fairly old fortran, and doesn't use pointers much.
But in general it just depends on which language you use.

I'd say that in my experience though, most of the work towards optimizing in scientific computing, both with respect to memory and speed, tends to be oriented towards optimizing at the mathematical/algorithmic level rather than at the programming-language/hardware level. That's where the big gains are to be had. Low-level optimization can often be a waste of time, given the rate at which hardware and compilers change.
 
  • #8
alxm said:
I'd say that in my experience though, most of the work towards optimizing in scientific computing, both with respect to memory and speed, tends to be oriented towards optimizing at the mathematical/algorithmic level rather than at the programming-language/hardware level.
To some degree, yes. A lousy algorithm is going to yield lousy performance regardless of the language in which it is implemented. Fine-tuning that lousy algorithm might yield a 10-20% boost in performance. Switching to a better algorithm might yield a n-fold boost.

On the other hand, even the best algorithm can be implemented stupidly. Passing by copy as opposed to reference, etc, can really slow things down.
 
  • #9
At least in C++, the goal is generally to use raw pointers only when absolutely necessary by letting the "dirty work" be hidden by things like STL containers and smart pointers.

However, you're still going to need to know how pointers work if you want to be proficient with C++ or C.
 
  • #10
Speedo said:
At least in C++, the goal is generally to use raw pointers only when absolutely necessary by letting the "dirty work" be hidden by things like STL containers and smart pointers.
... and references. Many development organizations prefer references over pointers if for no other reason than there is no such thing as a null reference. That said, some organizations ban call by non-const reference (e.g., google; http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Reference_Arguments [Broken]) because there is no "take the reference of" operator in C++. Suppose you see a function call foo (bar); in some code. There is no way to tell by looking at the function call alone whether bar is based as a value (i.e. a copy) or a reference. Not that I agree with that standard, but it is out there.

Regarding STL containers and smart pointers, some organizations ban the use of these. These same organizations are also likely to ban or strongly limit the use of new and delete (and malloc and free). That's because these organizations are building real-time / embedded software. A lot of avionics code is now written in C++.

However, you're still going to need to know how pointers work if you want to be proficient with C++ or C.
Agreed.
 
Last edited by a moderator:
  • #11
Mark44 said:
Assembly languages might not have pointers, per se, but the ones I'm familiar with, such as x86 and M68000, certainly have the concept of pointers, in which the contents of memory or a register are considered to be an address an memory, rather than just a plain value.
Depends on the machine. It's called indirect addressing mode, where memory contains an address instead of a value. It was (is?) used on some machines. On machines like x86 and 68000, there is no indirect addressing mode, so pointers require two steps, one to load the memory based address into a register, then to use the address in that register, optionally along with a fixed offset and/or a register based index. Page tables on x86 and 68000 mmu have arrays of pointers to pages for virtual to physical address translation. Caches also have arrays of addresses. DMA devices that also work in page mode will have an array of descriptor structures containing pointers and lengths to data in pages used for I/O.
 
Last edited:
  • #12
... and references. Many development organizations prefer references over pointers if for no other reason than there is no such thing as a null reference.

I was more speaking in terms of dynamic memory. You can't use references there (well, you can, but it's convoluted and back-asswards and frankly, anyone doing it should be shot).

That said, pass by [const] reference should pretty much be the default for non-POD function arguments in C++. I personally am in the "only use pointer arguments when the parameter is optional" camp. YMMV.

Regarding STL containers and smart pointers, some organizations ban the use of these. These same organizations are also likely to ban or strongly limit the use of new and delete (and malloc and free). That's because these organizations are building real-time / embedded software. A lot of avionics code is now written in C++.

Like pointers, you can't really call yourself proficient in C++ without knowing the SC++L (including STL), IMO. There will be times when you can't use all the language features because of system limitations or not so great implementations for your target platform, and in those circumstances you do what you have to. Most of the time though, you should be using those features.
 
  • #13
Speedo said:
I was more speaking in terms of dynamic memory. You can't use references there (well, you can, but it's convoluted and back-asswards and frankly, anyone doing it should be shot).
Sure you can. What's bass-ackwards about dereferencing a pointer, particularly before passing it to some function? There is a huge advantage to passing a reference versus passing a pointer: A reference cannot be null. The function with the pointer had dang well better have a test for a null pointer. That this function can throw an error, fail an assertion, or use some installation-specific error handling mechanism needs to be documented. A test case needs to be constructed to achieve 100% code coverage. The function that takes a reference does not have to do any of that stuff.

That said, pass by [const] reference should pretty much be the default for non-POD function arguments in C++.
The same goes for pointer arguments, unless of course the function truly is altering the contents of the object -- and that is ideally the only case in which the argument should be non-const.

I personally am in the "only use pointer arguments when the parameter is optional" camp. YMMV.
That is one of the more bizarre camps I've heard of -- and I've seen some doozies (e.g., the "no magic numbers" rule taken to such an extreme that one cannot use 0. One must use something along the lines of OVERLY_PEDANTIC_INSTALLATION_ZERO instead.)


ike pointers, you can't really call yourself proficient in C++ without knowing the SC++L (including STL), IMO. There will be times when you can't use all the language features because of system limitations or not so great implementations for your target platform, and in those circumstances you do what you have to. Most of the time though, you should be using those features.
I heartily disagree. This is a scientific site, one that deals primarily in physics and engineering related to physics. We are talking about scientific programming here. The mental skills needed to do the physical modeling needed for that scientific are quite distinct from the mental skills needed by a typical computer programmer.

From my experience, those skill sets are nearly orthogonal to one another. Scientists and engineers, for the most part, make for rather lousy programmers. So why do organizations involved in scientific programming even allow scientists and engineers to write code? The answer is simple: Lousy as the typical scientist/engineer may be regarding programming skills, the scientific reasoning skills of the typical computer programmer are even worse.
 

1) Are pointers necessary for all fields of scientific research?

No, pointers are not necessary for all fields of scientific research. They are mainly used in fields that require complex data structures, such as computer science and engineering. Other fields, such as biology or chemistry, may not require pointers as much.

2) How do pointers aid in scientific research?

Pointers allow scientists to efficiently manage and manipulate data. They allow for more flexibility in data structures, making it easier to organize and analyze large amounts of data. Pointers also enable scientists to easily pass data between functions, making their research more efficient.

3) Can pointers improve the accuracy of scientific results?

Yes, pointers can improve the accuracy of scientific results. By allowing scientists to efficiently manage and manipulate data, they can ensure that their data is organized and analyzed correctly. This can lead to more accurate and reliable results.

4) Are there any drawbacks to using pointers in scientific research?

One drawback of using pointers in scientific research is that they can be complex and difficult to understand for those who are not familiar with programming. This can make it challenging for collaboration between scientists from different fields. Additionally, incorrect use of pointers can lead to errors in data analysis.

5) How can scientists learn to use pointers effectively in their research?

Scientists can learn to use pointers effectively through training and practice. There are also many resources available, such as online tutorials and books, that can help scientists understand and utilize pointers in their research. Collaborating with experts in fields that heavily use pointers, such as computer science, can also be helpful in learning how to use them effectively.

Similar threads

  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
5
Views
848
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
19
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
10
Views
2K
Back
Top