Why implement DB connection pointer object as a reference counting pointer? (C++)
By : user1855598
Date : March 29 2020, 07:55 AM
this one helps. Probably it's a mistake. Without looking at the code it's impossible to know for sure, but the quality of the reference-counted pointer implementation is suggestive. Poor design, especially around resource management, is not unheard of in the C++ community. With that said, reference-counted pointers are useful when you have objects of indeterminate lifetime which are very expensive to create, or whose state needs to be shared among several users. Depending on the underlying architecture, database connections could fit this definition: if each database connection needs to authenticate over the global internet, say, it could easily be worth your trouble to save a single connection and reuse it, rather than making new connections and disposing of them as you go.
|
Basic JS implement basic math to convert a value
By : Jares
Date : March 29 2020, 07:55 AM
will help you Before everyone down votes, I have read hundreds of things and still lost as I don't know java at all and all examples found here I have been unable to get to work in my specific instance. I have only got far enough to understand the math I need but not how to apply to existing code I have to fix a problem. So greatly appreciate the help! , the problem was the percent = being in there. it simply needed to be code :
$test = (calculation);
$leftx = ($x / 788) * 100;
$leftx = (788 - $y) / 788 * 100;
$y = field_view_value('node', $node, 'simplepinitem_y', $field_y[0]);
$y = check_plain($y['#markup']);
$topy = (416 - $y) / 416 * 100;
$markers_html .= '<li style="top:' . $topy . '%;left:' . $leftx . '%" id="simplepinmap-pin-' . $i . '" class="simplepinmap-pins">' . theme('image', $marker) . '</li>';
|
Implement a stack by using a pointer to pointer
By : user2533392
Date : March 29 2020, 07:55 AM
I wish this help you Your push and pop functions are overly complicated and totally wrong: You want this: code :
void push(int **sp, int value) {
**sp = value; // put value onto top of the stack
(*sp)++; // increment stack pointer
}
int pop(int **sp) {
(*sp)--; // decrement stack pointer
return **sp; // return value which is on nthe op of the stack
}
void push(int **sp, int value) {
int *pt;
pt=&value; // here you put the pointer to the local variable value
// into pt, but local variables disappear as soon
// as the function has finished
// the printf is the only thing one more or less correct
// but you could just print directly 'value' like this:
// printf("Pushed value is %d\r\n", value);
//
printf("Push value is is %d\r\n", *pt);
sp = &pt; // this only assigns the pointer to the local variable pt to
// the local variable sp
++(*pt); // here you increment actually the local variable
// value which is pointless
}
int stack[10]; // no initialisation necessary
|
Basic RMA issue with MPI_Win_create, Null pointer in parameter NULL base pointer is invalid when size is nonzero
By : user3093132
Date : January 01 2021, 06:10 PM
Does that help The size argument of MPI_Win_create() has type INTEGER(KIND=MPI_ADDRESS_KIND). I was then able to successfully run the modified version with both MPICH 3.3 and the latest Open MPI code :
program main
use mpi
implicit none
integer :: ierr, procno, nprocs, comm
integer, allocatable :: root_data(:), local_data(:)
integer, parameter :: root = 0
integer (KIND=MPI_ADDRESS_KIND) :: NUM_ELEMENTS = 10, zero = 0
integer :: win
integer :: i
!======================================
call mpi_init(ierr)
comm = mpi_comm_world
call mpi_comm_rank(comm, procno, ierr)
call mpi_comm_size(comm, nprocs, ierr)
!======================================
if (procno .eq. root) then
allocate(root_data(1:NUM_ELEMENTS))
do i=1,NUM_ELEMENTS
root_data(i) = i
enddo
call mpi_win_create(root_data, NUM_ELEMENTS, MPI_INTEGER, MPI_INFO_NULL, comm, win, ierr)
else
allocate(local_data(1:NUM_ELEMENTS))
local_data = 0
call mpi_win_create(MPI_BOTTOM, zero, MPI_INTEGER, MPI_INFO_NULL, comm, win, ierr)
endif
!======================================
call mpi_win_fence(0, win, ierr)
!if (procno .ne. root) then
! call mpi_get(local_data, NUM_ELEMENTS, MPI_INTEGER, &
! root, 0, NUM_ELEMENTS, MPI_INTEGER, &
! win, ierr)
!endif
call mpi_win_fence(0, win, ierr)
!======================================
if (procno .ne. root) then
print *, "proc", procno
print *, local_data
endif
!======================================
call MPI_Win_free(win, ierr)
call mpi_finalize(ierr)
end program main
|
BigInt and indirection: is it feasible to implement BigInt with pointer-arithmetic on the pointer, for small values?
By : save_ferris
Date : March 29 2020, 07:55 AM
With these it helps On 32-bit machines, the lower two bits on pointers are almost always 0 because addresses are 32-bit aligned. Similarly, on 64-bit machines, the lower three bits will be 0. You can use this fact to use the least-significant bit of the pointer to tag whether it's a number or not. One simple option would be to set the LSB to 1 if it's a number and to 0 if it's a pointer. When performing arithmetic computations, you first check the LSB to see whether you have a pointer or an integer. If it's 1, you arithmetically right-shift the number over one bit to get the real integer value, then use that value in the computation. If it's 0, you simply follow the pointer to the representation.
|