allocation

Why does calling malloc() not make a difference?

早过忘川 提交于 2020-01-05 04:02:21
问题 Here's a basic example: #include <all the basic stuff> int main(void) { char *name = (char *) malloc(2 * sizeof(char)); if(name == NULL) { fprintf(stderr, "Error: Unable to allocate enough memory!\n"); return EXIT_FAILURE; } strcpy(name, "Bob Smith"); printf("Name: %s\n", name); free(name); return EXIT_SUCCESS; } Because I'm only allocating 2 bytes of information (2 chars), there should be some sort of error when I perform strcpy, right? This doesn't happen, instead it just copies the string

Why do subsequent Rust variables increment the stack pointer instead of decrementing it?

这一生的挚爱 提交于 2020-01-04 15:53:49
问题 I find it odd how when you create statically-allocated variables in Rust that it seems as the stack pointer increases. I know this is not the case since the stack pointer decreases as memory is allocated. If I were to do the same thing in C, I would see the stack pointer decrease as I created more variables. Why is it this way? Does the Rust compiler allocate these from bottom to top instead on top to bottom? fn main() { let i1 = 1; let i2 = 1; let i3 = 1; println!("i1 : {:?}", &i1 as *const

Android - view.Surface OutOfResourcesException

笑着哭i 提交于 2020-01-03 17:03:39
问题 My Android app seems to not be releasing its views when I move around inside of it with ListView navigation and with the standard Menu key. After a hundred or so different (of the 10 or so unique views) loads, it starts lagging and black screening. Error log: 07-01 09:54:42.913: INFO/ActivityManager(1279): Starting: Intent { cmp=com.site.android.conferencecompanion/.Search } from pid 31290 07-01 09:54:43.013: ERROR/msm7x30.gralloc(1279): /dev/pmem: no more pmem available 07-01 09:54:43.013:

C++ Memory allocation. Matrix

筅森魡賤 提交于 2020-01-03 04:52:13
问题 I looked into two different method to allocate memory for the elements of a matrix Method n.1 int** matrix = new int*[rows]; for (int i = 0; i < rows; ++i) matrix[i] = new int[cols]; Method n.2 int** matrix = new int*[rows]; if (rows) { matrix[0] = new int[rows * cols]; for (int i = 1; i < rows; ++i) matrix[i] = matrix[0] + i * cols; } I can figure out what Method n.1 does, but I can't figure out what exactly is supposed to do the if clause in Method n.2 (I would implement it without and it

Spritekit: Efficiently create many SpriteNodes

不打扰是莪最后的温柔 提交于 2020-01-03 03:14:29
问题 I am using SpriteKit to write a bullet-hell style shoot-em-up, and the SK framework seems to be able to handle hundreds of nodes at 60fps without any problems at all. My problem however is that sometimes I need to spawn 50+ nodes in a single frame, and that does seem to cause the odd hitch in framerate. Are there any tricks I should be using to make sure that creation of many nodes is as performant as possible? I am re-using SKTextures, should I also have a persistent collection of

Can a input argument of a Fortran subroutine be deallocated and allocated in the body of the subroutine?

孤街浪徒 提交于 2020-01-03 02:11:47
问题 UPDATE: My modified code looks like this: program run_module_test use module_test implicit none TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:) call update(xyzArray) write(6,*)'xyzArray',xyzArray end program run_module_test module module_test implicit none TYPE :: newXYZ real(4) :: x, u real(4) :: y, v real(4) :: z, w real(4),dimension(3) :: uvw END TYPE integer(4) :: shape = 3 contains subroutine update(xyzArray) integer(4) :: i TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)

Can a input argument of a Fortran subroutine be deallocated and allocated in the body of the subroutine?

情到浓时终转凉″ 提交于 2020-01-03 02:11:20
问题 UPDATE: My modified code looks like this: program run_module_test use module_test implicit none TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:) call update(xyzArray) write(6,*)'xyzArray',xyzArray end program run_module_test module module_test implicit none TYPE :: newXYZ real(4) :: x, u real(4) :: y, v real(4) :: z, w real(4),dimension(3) :: uvw END TYPE integer(4) :: shape = 3 contains subroutine update(xyzArray) integer(4) :: i TYPE(newXYZ), allocatable, intent(inout) :: xyzArray(:)

Calculate vector whose length is not known beforehand - should I “grow” it?

跟風遠走 提交于 2020-01-01 08:45:09
问题 I need to calculate entries of a vector whose length I do not know beforehand . How to do so efficiently? A trivial solution is to "grow" it: start with a small or empty vector and successively append new entries until the stopping criterion is reached. For example: foo <- numeric(0) while ( sum(foo) < 100 ) foo <- c(foo,runif(1)) length(foo) # 195 However, "growing" vectors is frowned upon in R for performance reasons. Of course, I could "grow it in chunks": pre-allocate a "good-sized"

realloc structure with function in C

与世无争的帅哥 提交于 2019-12-31 07:21:09
问题 My C program is crashing and I am too new to figure it out. It's very simple so far and I imagine the code is enough to figure out what is going wrong. I am simply trying to read a file line by line. I will double the memory of a structure once I am out of memory. If this is not enough information, I will give whatever else you need. Thank you very much for any help, as I have been stuck for hours now. /* John Maynard 1000916794 7/15/2013 HW-06 */ #include <stdio.h> #include <stdlib.h>

Dynamic Memory Allocation

人盡茶涼 提交于 2019-12-31 03:11:06
问题 I'm having trouble dynamically allocating memory for an array. I've been debugging for hours, any pointers? I posted the rest of the code. It is simply supposed to exchange the swap the first row with the second, and the third with the forth. I am getting strange results like: Enter string: hello Enter string: how are you Enter string: i'm good thanks Enter string: bye Enter string: bai Enter string: xx ========================= how are you !i'm good thanks hello !how are you bye !bai i'm