3

Okay there, i have some code in python that opens a file -> process it -> and writes data to other file.

def ELECrypt(myFile, outFile, code):
    Code = list(bytes(code,'utf-8'))
    with open(myFile, 'rb') as bFil:
        with open(outFile, 'wb') as bOutFil:
            while True :
                data = bytearray(bFil.read(CHUNK_SIZE))
                if not data: break
                processIt(data, Code)
                bOutFil.write(data)

It works fine, but it is too slow. So, i wrote a C++ program that does similar thing and I want to know if it is possible to make it callable from python

#include <iostream>
#include <fstream>
using namespace std;
int CHUNK_SIZE = 1*1024*1024;
void ELECrypt(ifstream& myFile, ofstream& outFile, unsigned char Code[], int CodeLen){
    unsigned char* fChunk = new unsigned char[CHUNK_SIZE];
    int readCount;
    while (myFile.read((char *)fChunk, CHUNK_SIZE) || myFile.gcount() > 0)
    {
        ...Processing a data block
        outFile.write((char *)fChunk, myFile.gcount());
    }
    delete [] fChunk;
}

Yeah-yeah, I know there might be a lot of work, but i can`t even find where to read about arguments that can be passed by python to c++ extension

3
  • Have you checked that it is actually performing measurably better? Commented Nov 30, 2017 at 18:57
  • You can try swig. swig.org Commented Nov 30, 2017 at 18:59
  • @EugeneSh. yes, on an image if 6.4mb C++ works like less then second, and python like more then 10 seconds Commented Nov 30, 2017 at 19:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.