pointers

Accessing memory larger than UINT_MAX*4 size in C?

Hello, Assume if I have an array of size 78719476736 bytes. mind you that this array is dynamically allocated using malloc in my C code. Assume malloc returns a valid pointer after allocating this much memory. The size of this array is more than UINT_MAX(4294967295) , i.e. max limit of a unsigned int(32 bits) Assume my code looks like ...

Pointers in C# and how frequently it is used in the application?

For me , the Pointer was one of the hardest concept in programming languages in C++. When I was learning C++, I spent tremendous amount of time learning it. However, Now I primarily work in projects that are entirely written in languages like C#, and VB.NET etc. As a matter fact, I have NOT touched C++ for almost 4 years. Even though, C...

C++, ways to benchmark improvements in cache locality?

I have an implementation of a class X, that has two pointers to two pieces of information. I have written a new implementation, class Y, that has only one pointer to a struct that contains the two pieces of information together as adjacent members. X's and Y's methods usually only need to manipulate one of the pieces of information, but ...

Pointer arithmetic on string type arrays, how does C++ handle this?

I am learning about pointers and one concept is troubling me. I understand that if you have a pointer (e.g.'pointer1') of type INT that points to an array then you can fill that array with INTS. If you want to address a member of the array you can use the pointer and you can do pointer1 ++; to step through the array. The program knows th...

Fast method to read and store serialized objects with pointers and pointers to pointers in C++

I'm needing a fast method to read and store objects with pointers and pointers to pointers in xml files in c++ . Every object has it's own id , name , and class type. ...

How do I convert something of "string*" to "const string&" in C++?

For example, if I have the following: void foo(string* s) { bar(s); // this line fails to compile, invalid init. error } void bar(const string& cs) { // stuff happens here } What conversions do I need to make to have the call the bar succeed? ...

Why don't I declare NSInteger with a *

I'm trying my hand at the iPhone course from Stanford on iTunes U and I'm a bit confused about pointers. In the first assignment, I tried doing something like this NSString *processName = [[NSProcessInfo processInfo] processName]; NSInteger *processID = [[NSProcessInfo processInfo] processIdentifier]; Which generated an error, after t...

How does an array of pointers to pointers work?

char **Data[70]={NULL}; What is the correct terminology for this? How else could it be written? What does it look like in memory? I am reading many tutorials on pointers but I don't see it in this syntax. Any help is appreciated. Thanks. ...

Passing pointers to function

Hi, I have a doubt in my program #include<stdio.h> int myFunc(char **); main() { char *a[2]={"Do","While"}; myFunc(a); } int myFunc(char **P) { /* Here I want to print the strings passed but I'm unable to print the strings I just tried the below statement which printed just the first letter which is 'D'*/ ...

making numerous pointers NULL at the same time

This is a C++ class that I have made with n number of pointers. class SomeClass { private: int* ptr1; int* ptr2; ... int* ptrn; private: // constructors, destructors, and methods }; During the initialization stage, I want to make all those pointers point to NULL (or make pointers point to NULL by default when...

How to generate C++ Dynamic Objects names ?

I'd like to generate a number of objects (in C++) based on the amount/number the user enters. Now I've somewhere heard that it has to be done using pointer tricks, creating a pointer to an array of the Object type required, and then dynamically increasing the size of array ( at runtime ). Isn't there a workaround of directly using name...

Dynamic Multidimensional array

I need a multidimensional array of chars that is dynamic in only one dimension... I have to store a pair of strings with a length of 10 (or less) chars each, but with a variable number of "pairs". My idea was this char (*instrucao)[2][10]; Which gives me a pointer to a 2x10 array of chars, but this is not working properly when i do s...

When to use a void pointer?

I understand the use of void pointer for malloc implementation. void* malloc ( size_t size ); Can anyone suggest other reasons or provide some scenarios where it is useful in practice. Thanks ...

doubts in double pointer in C

the follwing code is run successfully ... typedef struct _s { int *r; }s; void main() { s *u; int y=1000; u=malloc(sizeof(s)*8); u->r=malloc(sizeof(int)*8); u->r[5]=y; printf("%d\n",u->r[5]); getch(); } but i write the follwing code as above but gives error ....i use structure.....may why i know the reaso...

Any way to detect whether the pointer points to array?

Hi, everyone! Is there any way to detect, whether the pointer points to array in C++? My problem is that I want to implement a class, that becomes the owner of the array. My class is initialized with the pointer and I would like to know, whether the pointer is really an array pointer. Here is the simplified code: class ArrayOwner { pub...

Creating arrays on the heap and addressing them with pointers

Hi, I'm having trouble understanding the following bit of code that I was hoping would create an array on the heap and fill it with the characters 9 down to 0 (I know I could just index the array like a normal stack array with [] notation to do this but I'm doing it this way to try to understand pointers in more depth): int *ptrHeapArra...

C++ pointer-to-char question

char *ps; ps = &anotherChar; cout << ps; Why this displays the value of anotherChar not just the address?. ...

C++ overflow with new keyword debugging

I'm having a tricky debugging issue, perhaps due to my lack of understanding about how c++ manages memory. The code is too long to post, but the essential setup is as follows: global_var = 0; int main() { for(i = 0; i < N; ++i) { ClassA a; new ClassB(a); // seems to be problem! } } For some N, global_var gets corrupted (i...

Newbie pointer/array notation question

Suppose I have: unsafe { byte* start = GetStartLocation(); int something = start[4]; } What is 'something'? The value of the memory address 4 bytes down from start? ...

Problems to use pointers within a compiler

I'm trying to complete an analexical validation but I'm facing some trouble with pointers, this is my code case 6: c = next_carac(file); for(handle=0;(words[handle] != "NULL");handle++) { strcpy(message, words[handle]); if(!strcmp(token,message)) strcpy(message, "words"); } if(isdigit(c) && strcmp(message,"word...