/
/
i have another question
/
i have this function
inline void readSamples ()
{
step ( 4 );
soundfont.samplesCount = read < uint32_t > () / 46;
for ( int i = 0; i != soundfont.samplesCount; i++ )
{
auto name = readBytes ( 20, true );
auto sampleFrom = read < uint32_t > ();
auto sampleTo = read < uint32_t > ();
uint32_t samplesCount = sampleTo - sampleFrom;
uint32_t samplesSize = samplesCount * 2;
auto * temp_sample_aData = new int16_t [ samplesCount ];
memcpy ( reinterpret_cast < char * > ( temp_sample_aData ), audio_data + sampleFrom, samplesSize );
Sample sample ( name, i, temp_sample_aData, read < uint32_t > (), read < uint32_t > (), read < uint32_t > (), samplesSize );
samples.push_back ( sample );
step ( 6 );
}
operator delete [] ( audio_data );
}
how can i delete the part of the buffer i have readed after reading it
/
but only the part i have readed not everything
/
someone know
Amine
Pavel
i have this function
inline void readSamples ()
{
step ( 4 );
soundfont.samplesCount = read < uint32_t > () / 46;
for ( int i = 0; i != soundfont.samplesCount; i++ )
{
auto name = readBytes ( 20, true );
auto sampleFrom = read < uint32_t > ();
auto sampleTo = read < uint32_t > ();
uint32_t samplesCount = sampleTo - sampleFrom;
uint32_t samplesSize = samplesCount * 2;
auto * temp_sample_aData = new int16_t [ samplesCount ];
memcpy ( reinterpret_cast < char * > ( temp_sample_aData ), audio_data + sampleFrom, samplesSize );
Sample sample ( name, i, temp_sample_aData, read < uint32_t > (), read < uint32_t > (), read < uint32_t > (), samplesSize );
samples.push_back ( sample );
step ( 6 );
}
operator delete [] ( audio_data );
}
how can i delete the part of the buffer i have readed after reading it
Not sure if I understand you. What buffer, and what do you mean by deleting the part?
If you use C-arrays, then you can't really delete part of it, since the allocated memory should be deallocated in a whole.
If you use std::vector you can use erase to remove part of the elements, but that will also keep the memory allocated to be reused later. You can however call shrink_to_fit which will reallocate the vector data to shrink the size of the allocated block (it is slow because of allocation, and will make next additions to the vector slow)
Amine
Amine
#include <stdio.h>
int main() {
int length = 5;
for(int i=0 ; i <length ; i++){
for(int j=0 ; j < length-i; j++){
printf(".");
}
for(int k=0 ;k<=i ;k++ )
printf("*");
printf("\n");
}
return 0;
}
/
/
Pavel
浩
Hello, I have the following cmake code:
add_library(A_LIB_NAME_HERE INTERFACE)
...
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
target_link_libraries(A_LIB_NAME_HERE INTERFACE ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
...
install(TARGETS A_LIB_NAME_HERE EXPORT A_LIB_NAME_HERE-target)
install(EXPORT A_LIB_NAME_HERE-target FILE A_LIB_NAME_HERE-config.cmake DESTINATION lib/cmake/A_LIB_NAME_HERE)
The result xxx-config.cmake contains ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} directly.
I want to let it contains
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
target_link_libraries(A_LIB_NAME_HERE INTERFACE ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
that is to say find BLAS and LAPACK when using the library after installation, instead of when installing.
How to do it?
/
/
/
new int16_t [ sizw ]
/
/
Pavel
but if i use a vector do it use more memory
It depends, it usually preallocates some memory in advance to decrease amount of allocations (if it wouldn't do that, every addition of an element would be an allocation and copying all existing elements to the new memory).
But you can control that, you can ask to preallocate memory for the the desired amount of elements by calling reserve, or just create them right away with resize. As far as I remember, both of them should allocate only memory needed to fit them and no more. You can check that yourself by checking value of what capacity returns.
/
Pavel
I mean if you can reliably allocate big enough chunk of memory for it on your target platform
/
/
Pavel
/
Lawal
Hi
кар карыч
hello, I ran into a problem that Visual Studio 2017 gives errors in standard libraries, writes that "C2143 syntax error: missing ")" before "constant" x) C"
кар карыч
and so in many files like math.h
A
https://leetcode.com/problems/reverse-bits/discuss/2283682/Help-needed-C%2B%2B-code
A
help needed here can anyone help me out
A
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t q=pow(2,31);
uint32_t b = 0;
if( n == 0){
return b;
}
for(uint32_t i=1;i<=(q-1);i++){
if(n & 1){
b = b | 1;
b = b << 1;
n = n >> 1;
}
else{
b = b | 0;
b = b << 1;
n = n >> 1;
}
}
return b;
}
};
A
code to reverse bits of integer
Submissive
#include <bits/stdc++.h>
using namespace std;
void removeDupWord(string str)
{
string word = "";
for (auto x : str)
{
if (x == ' ')
{
cout << word << endl;
word = "";
}
else {
word = word + x;
}
}
cout << word << endl;
}
// Driver code
int main()
{
string str = "Geeks for Geeks";
removeDupWord(str);
return 0;
}
This code splits the line into words
What does that for loop mean? Can we use colon inside for loop()
Buffer
Buffer
It is the semicolon form of for loop
Buffer
That was range based for loop in c++ and added since c++ 11
Shappa
Where do I start as a newbie
Shappa
!?
المبرمج طارق
Sylvester Lim
Hi all, I am making a game where each player will pick a card and then see who wins, then this repeats for 5 rounds ... and they can choose whether to continue playing after the 5 rounds or not. I want to output the game logs into an output file where I used this method below :
int main{
do{
recordGameLogs(); // i call my function to record game logs here
}while(round <=5) //make the game run for 5 rounds
return 0;
}
void recordGameLogs()
{
ofstream outfile;
outfile.open("testwritezzz.txt", ios::app); // i used append mode to make sure that data is not overwritten after every round(as the game is played for at least 5 rounds)
if(outfile)
{
outfile << "Game Log --> Round " << roundNum <<endl;
outfile << "________________________________" << endl;
outfile << "(all player details etc etc)"
}
The code I sent is not complete, I just wanted to show a rough skeleton of the program. Anyways I used ::app , which is append mode to make the data be succesffuly written for all 5 rounds, if I just left it without append mode or trunc mode, the output file only records Round 5 details(as round 1 to 4 details are being overwritten). However, if i were to exit the program and decide to run it again , the previous game logs are still there. Is there any way for it to clear previous output content when the program is terminated, so everytime I run it only records the newest 5 rounds played .
Anonymous
Anyone up for pair programming?
/
hi i have a problem
/
std::ifstream * file;
bool open ( char * fileName )
{
file -> open ( fileName, std :: ios :: binary );
return file -> is_open ();
}
/
why this crashes
/
it isnt a problem of the file name
Sandy
😄
/
/
i have solved it
/
but how i get the current offset with fstream
/
the position
pavel
/
i tried tellg it returns 0
/
no wait it doesnt
Kirk
hi, i'm having problems initializing a bi-dimensional vector in a class:
https://pastebin.com/RYAH2Q2D
compiling with g++ i get "error: ‘V’ is not a type"
Saleh
hello
i can't use include filesystem on codeblock 13.12
how i can solve that problem?
Saleh
Usha
Hi anyone there to start from basics?
Pavel
Saleh
\Device\NUL
*Confused nick young
Anonymous
pavel
pavel
Saleh
\Device\NUL