Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
What's up?
I am very interested in the question of how to add a new element to my array
uint32 glfw_extension_count = 0;
const char** glfw_extensions;
glfw_extensions = glfwGetRequiredInstanceExtensions(&glfw_extension_count);
return glfw_extensions;
I just need add to 'glfw_extensions' VK_EXT_DEBUG_UTILS_EXTENSION_NAME
The (great!) documentation says:
Pointer lifetime
The returned array is allocated and freed by GLFW. You should not free it yourself. It is guaranteed to be valid only until the library is terminated.
So clearly you can't do the necessary re-allocation. So you must allocate a new array, copy the data in, and then append your additional entry. I would assume that you can safely copy the string pointers themselves, didn't see a lot of discussion about that in the documentation page so it might need further verification.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
This is my array of arraylist: Arraylist[] a = new Arraylist[SIZE];
I’m struggling with writing it in my UML diagram, how can I write it?
With or without the <>?
The simplest way is to define it this way:
a is of type Arraylist (after the colon) with multiplicity 0..* and its default (after the equal sign) is Arraylist[SIZE].
As commented by #bruno the default value is a bit of interpretation. UML basically should be held language agnostic, but sometimes you just want to point out implementation details (for whatever reason). So you can add the new keyword right in front of the Arraylist[SIZE]. What that actually means is language dependent (and so out of a general scope I like to stick to).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I was wondering if there is a possibility to shift a whole block in an array. I intend to delete one item in an array of dynamic length, and after I deleted it, I want the whole block to shift to the right. So far I do this element, by element, but this is not efficient. So I was wondering if there is a better solution.
Important: the order of the elements needs to be kept the same.
Using memmove will probably be more efficient than doing an element by element copy as then you can take advantage of the fact you're doing a bulk move rather than lots of little moves (and compilers often provide highly optimized memmove implementations), but that's about it. You need to move everything around in memory, so you're going to have to move it.
If you're doing this a lot with your arrays, it probably means you need a different data structure.
You can use linked list instead of array. In linked list deleting is easy. You just have to point the next next elements.
Use a ring buffer, like this:
unsigned idx;
int Buf[1024];
void EnterValue(int value)
{
idx++;
Buf[idx & 1023] = value;
}
int GetOldValue(unsigned age)
{
assert(age<1024);
return Buf[ (idx-age) & 1023 ];
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
The const value can be changed inside the stack using pointer.But we can not modify the value of a const variable when it is defined globally.Because it goes to the RO data section.So this value is protected.But inside a stack the const variable doesn't provide protection.Why..?..If it is not providing any protection means then what is the use of const value inside the stack.?.
When you use the const keyword you just tell the compiler to throw error when you try to assign this variable, but it doesn't protect memory.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 170 png images in a folder.
I want to load and store them in a matrix/array/cell array, so that i can easily access and modify them but I'm stuck at the very beginning.
How can I do it? Which is the best structure?
Assuming they are all the same size, in the folder containing the images:
list=dir('*.png'); % read all the .pngs in your folder
Image1=imread(list(1).name); % read the first image to calculate the dimentions of your stack
ImSize=size(Image1)
ImageStack=zeros(ImSize(1),ImSize(2),length(list)); % preallocate your stack with zeros
for ii=1:length(list)
Image=imread(list(ii).name
ImageStack(:,:,ii)=rgb2gray(Image); % copy an image in each step of the third dimsion of your stack
end
If you need the color information just add another dimension to ImageStack and forget the rgb2gray(). Hope that helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a function
void join(table first, void(*pfapply)(const char *inp1,const void *inp2,void *addn),const void *addn);
here first is a instance of structure table as below
struct table
{
char inp1;
int inp2;
}struct table *first;
Now how to add this extra variable "addn" in this "join function"
In my symbol table i have two values inp1 and inp2..how to add addn to my structure using the above function?
I need to bind addn to the two variables inp1 and inp2...
The addn is probably just the API being friendly and providing support for an additional parameter to the pfapply() callback.
This is a sign of good design, since it allows the callback to access some of its data without having to make it global.
If you don't need any additional data, just ignore the argument inside your apply-function, and call join() with NULL as the third argument.
You don't need to change anything in the declaration of table, all is fine.