Questions tagged [pointer-aliasing]
59 questions
0
votes
2 answers
Java Collections & aliasing
How do you deal with aliasing in Java? A simple solution is to make a copy of let's say an ArrayList but when i try to write the code my data keeps being overwritten by newly added data. In detail:
ArrayList temp = new…
user425727
0
votes
2 answers
Using negative array index to access preceeding member
I'd like to use a negative array index to access the same-type member that immediately precedes that array in a struct.
Consider this type of code:
union hello {
int a[2];
struct { int b0; int b1[1]; };
};
I want to use b1[-1] to access b0.…

Filipp
- 1,843
- 12
- 26
0
votes
1 answer
Attempting to alter a copy but instead altering the original :(
I'm trying to make a 'smart' opponent in my Tic Tac Toe program. To do this I've created a 'possible win' function which will decide if there is a possible win in the next turn. My problem when running this code is that on every iteration of the for…

JTinHearth
- 3
- 2
0
votes
1 answer
using aliasing to iterate through list once (python)
Say I have a list called list, which is comprised of boolean values. Also say that I have some (valid) index i which is the index of list where I want to switch the value.
Currently, I have: list[i] = not list[i].
But my question is, doesn't this…

user1519226
- 77
- 2
- 12
0
votes
1 answer
Does NumPy handle 1:1 aliasing of complex-number operations correctly?
Say a and b are disjoint 1D complex NumPy arrays, and I do numpy.multiply(a, b, b).
Is b guaranteed to contain the same values as I would get via b[:] = numpy.multiply(a, b)?
I haven't actually been able to produce incorrect results, but I don't…

user541686
- 205,094
- 128
- 528
- 886
0
votes
2 answers
Strict aliasing and writing int via char*
In an old program I serialized a data structure to bytes, by allocating an array of unsigned char, and then converted ints by:
*((*int)p) = value;
(where p is the unsigned char*, and value is the value to be stored).
This worked fine, except when…

Morty
- 1,706
- 1
- 12
- 25
0
votes
2 answers
Deallocating item in array
It if have an object, lets call it o, and two arrays typeo *a,*b; if I assign o to both array a and array b then delete[] b what happens if I try to access o or o in a? For example:
struct name{int a;}
name *a = new name[1];
name *b = new…

Hovestar
- 1,544
- 4
- 18
- 26
0
votes
4 answers
Unable to overwrite pathInfo in a Symfony 2 Request
I'm trying to deal with aliases (friendly-urls) and probably I'm not doing it right. What I want to do is to transform urls like '/blog/my-post-about-something' into '/posts/23'.
I have written a listener for the kernel.request event that makes some…

carles
- 360
- 4
- 16
0
votes
0 answers
Pointer aliasing and Performance improvement
Quick question (hopefully it is clear).
I was told that performance when considering speed can be drastically improved if you handle the problem of pointer aliasing (always reloading values from memory because compiler isn't sure the value pointed…

user3332240
- 21
- 1
- 2
0
votes
1 answer
Aliasing in objects
When running the function foo1, why does the output for this code will be: 15 30 5
and not 15 15 5 ?
I underdtand that the pointer of the object v is now points to the object va1, so the output for the code line: System.out.print(v.getI() + "…
0
votes
1 answer
Aliasing example, try to understand this issue
I try to learn about Aliasing and encounter this example:
public class A
{
// Instance variable
private double _x;
// 3 constructors
public A(double x)
{
_x = x;
}
public A()
{
_x = 0;
}
…

user979033
- 5,430
- 7
- 32
- 50
0
votes
1 answer
setObject() Method and aliasing
I have a LINE class that has two attributes of type POINT (which is an object).
public class LINE {
private Point p1,p2;
}
If I make this statement, will it cause aliasing?
public void setP1(Point p1)
{
this.p1=p1;
}
Or Do I have to create a…

Assaf
- 1,112
- 4
- 14
- 35
-2
votes
1 answer
Algorithms, 4th Edition: do not understand an example about aliasing/reference
Counter c1 = new Counter("ones");
c1.increment();
Counter c2 = c1;
c2.increment();
StdOut.println(c1);
class code link: https://introcs.cs.princeton.edu/java/33design/Counter.java
public class Counter implements Comparable {
…

Clifford
- 1
- 2
-3
votes
1 answer
What happens behind the scenes(heap,stack,etc..) when adding a Node to the a LinkedList?
public void addToHead(IntNode node) {
IntNode temp = _head;
_head = node;
node.setNext(temp);
}
edit:I searched youtube, Nothig there about linkedlist and the heap
When does the garbage collector wipe temp? I know it should, but can't…

Arik Shalito
- 1
- 5