What does “MemoryError: Stack overflow” mean while releasing memory using CFFI?Why my app crashes when I free a char* allocated by a DLL generated with CFFI?What does the explicit keyword mean?What does asterisk * mean in Python?What does the star operator mean?What does int argc, char *argv[] mean?In Matplotlib, what does the argument mean in fig.add_subplot(111)?What does “dereferencing” a pointer mean?What does T&& (double ampersand) mean in C++11?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?What does enumerate() mean?How does the memory release for big return values (such as string) happen in C++?
What does "tea juice" mean in this context?
Is there an evolutionary advantage to having two heads?
Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?
My player wants to cast multiple charges of magic missile from a wand
How can a single Member of the House block a Congressional bill?
chmod would set file permission to 000 no matter what permission i try to set
Is this light switch installation safe and legal?
How do I subvert the tropes of a train heist?
Could IPv6 make NAT / port numbers redundant?
How to detach yourself from a character you're going to kill?
Differences between “pas vrai ?”, “c’est ça ?”, “hein ?”, and “n’est-ce pas ?”
When a current flow in an inductor is interrupted, what limits the voltage rise?
Where did the “vikings wear helmets with horn” stereotype come from and why?
Do Multiclassed spellcasters add their ability modifier or proficiency bonus twice when determining spell save DC?
Expenditure in Poland - Forex doesn't have Zloty
Did airlines fly their aircraft slower in response to oil prices in the 1970s?
Uncommanded roll at high speed
Select row of data if next row contains zero
How to make the POV character sit on the sidelines without the reader getting bored
California: "For quality assurance, this phone call is being recorded"
Why the lack of hesitance to wear pads on the sabbath?
What does the behaviour of water on the skin of an aircraft in flight tell us?
Term for checking piece whose opponent daren't capture it
What's the most polite way to tell a manager "shut up and let me work"?
What does “MemoryError: Stack overflow” mean while releasing memory using CFFI?
Why my app crashes when I free a char* allocated by a DLL generated with CFFI?What does the explicit keyword mean?What does asterisk * mean in Python?What does the star operator mean?What does int argc, char *argv[] mean?In Matplotlib, what does the argument mean in fig.add_subplot(111)?What does “dereferencing” a pointer mean?What does T&& (double ampersand) mean in C++11?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?What does enumerate() mean?How does the memory release for big return values (such as string) happen in C++?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question follows this one.
I use CFFI to create a DLL and I call it from a C++ application. I was questioning myself to find how to release memory allocated by the DLL and I follow the idea mention by @metal in its answer.
Here is now my Python code:
import cffi
ffibuilder = cffi.FFI()
ffibuilder.embedding_api('''
char* get_string();
void free_char(char*);
''')
ffibuilder.set_source('my_plugin', '')
ffibuilder.embedding_init_code('''
from my_plugin import ffi, lib
@ffi.def_extern()
def get_string():
val = "string"
return lib.strdup(val.encode())
@ffi.def_extern()
def free_char(ptr):
lib.free(ptr)
''')
ffibuilder.cdef('''
char *strdup(const char *);
void free(void *ptr);
''')
ffibuilder.compile(target='my-plugin.*', verbose=True)
And my C++ code:
#include <iostream>
#include <windows.h>
typedef char* (__stdcall *get_string_t)();
typedef void (__stdcall *free_char_t)(char*);
int main()
HINSTANCE hGetProcIDDLL = LoadLibrary("my-plugin.dll");
if (!hGetProcIDDLL)
std::cout << "could not load the dynamic library" << std::endl;
return -1;
get_string_t get_string = (get_string_t)GetProcAddress(hGetProcIDDLL, "get_string");
if (!get_string)
std::cout << "could not locate the function" << std::endl;
return -1;
free_char_t free_char = (free_char_t)GetProcAddress(hGetProcIDDLL, "free_char");
if (!free_char)
std::cout << "could not locate the function" << std::endl;
return -1;
for(int i = 0; i < 25000000; i++)
char* val = NULL;
val = get_string();
if(i % 10000 == 0)
std::cout << "Value " << i << " = " << val << std::endl;
if(val)
free_char(val);
std::cout << "End" << std::endl;
return 0;
I get this result:
Value 0 = string
Value 10000 = string
Value 20000 = string
Value 30000 = string
Value 40000 = string
Value 50000 = string
Value 60000 = string
Value 70000 = string
Value 80000 = string
Value 90000 = string
Value 100000 = string
Value 110000 = string
Value 120000 = string
Value 130000 = string
Value 140000 = string
Value 150000 = string
Value 160000 = string
Value 170000 = string
Value 180000 = string
Value 190000 = string
Value 200000 = string
Value 210000 = string
Value 220000 = string
Value 230000 = string
Value 240000 = string
Value 250000 = string
From cffi callback <function get_string at 0x03470810>:
MemoryError: Stack overflow
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
What does this error mean? I don't have memory problem because I release memory with my new free_char
function. By the way, if I remove the call to free_char
I can make all the loops (but the memory is not release).
python c++ memory-management python-cffi
add a comment |
This question follows this one.
I use CFFI to create a DLL and I call it from a C++ application. I was questioning myself to find how to release memory allocated by the DLL and I follow the idea mention by @metal in its answer.
Here is now my Python code:
import cffi
ffibuilder = cffi.FFI()
ffibuilder.embedding_api('''
char* get_string();
void free_char(char*);
''')
ffibuilder.set_source('my_plugin', '')
ffibuilder.embedding_init_code('''
from my_plugin import ffi, lib
@ffi.def_extern()
def get_string():
val = "string"
return lib.strdup(val.encode())
@ffi.def_extern()
def free_char(ptr):
lib.free(ptr)
''')
ffibuilder.cdef('''
char *strdup(const char *);
void free(void *ptr);
''')
ffibuilder.compile(target='my-plugin.*', verbose=True)
And my C++ code:
#include <iostream>
#include <windows.h>
typedef char* (__stdcall *get_string_t)();
typedef void (__stdcall *free_char_t)(char*);
int main()
HINSTANCE hGetProcIDDLL = LoadLibrary("my-plugin.dll");
if (!hGetProcIDDLL)
std::cout << "could not load the dynamic library" << std::endl;
return -1;
get_string_t get_string = (get_string_t)GetProcAddress(hGetProcIDDLL, "get_string");
if (!get_string)
std::cout << "could not locate the function" << std::endl;
return -1;
free_char_t free_char = (free_char_t)GetProcAddress(hGetProcIDDLL, "free_char");
if (!free_char)
std::cout << "could not locate the function" << std::endl;
return -1;
for(int i = 0; i < 25000000; i++)
char* val = NULL;
val = get_string();
if(i % 10000 == 0)
std::cout << "Value " << i << " = " << val << std::endl;
if(val)
free_char(val);
std::cout << "End" << std::endl;
return 0;
I get this result:
Value 0 = string
Value 10000 = string
Value 20000 = string
Value 30000 = string
Value 40000 = string
Value 50000 = string
Value 60000 = string
Value 70000 = string
Value 80000 = string
Value 90000 = string
Value 100000 = string
Value 110000 = string
Value 120000 = string
Value 130000 = string
Value 140000 = string
Value 150000 = string
Value 160000 = string
Value 170000 = string
Value 180000 = string
Value 190000 = string
Value 200000 = string
Value 210000 = string
Value 220000 = string
Value 230000 = string
Value 240000 = string
Value 250000 = string
From cffi callback <function get_string at 0x03470810>:
MemoryError: Stack overflow
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
What does this error mean? I don't have memory problem because I release memory with my new free_char
function. By the way, if I remove the call to free_char
I can make all the loops (but the memory is not release).
python c++ memory-management python-cffi
I just made a test with python2.7 building cffi with visual compiler aka.ms/vcpython27 and building C++ with Visual 2017, your code run till the end without problems. Which compiler did you used ?
– mpromonet
Mar 24 at 11:10
@mpromonet I usecl.exe
in Visual Studio 2010 and the last version of Python (3.7.2).
– Pierre
Mar 24 at 11:11
add a comment |
This question follows this one.
I use CFFI to create a DLL and I call it from a C++ application. I was questioning myself to find how to release memory allocated by the DLL and I follow the idea mention by @metal in its answer.
Here is now my Python code:
import cffi
ffibuilder = cffi.FFI()
ffibuilder.embedding_api('''
char* get_string();
void free_char(char*);
''')
ffibuilder.set_source('my_plugin', '')
ffibuilder.embedding_init_code('''
from my_plugin import ffi, lib
@ffi.def_extern()
def get_string():
val = "string"
return lib.strdup(val.encode())
@ffi.def_extern()
def free_char(ptr):
lib.free(ptr)
''')
ffibuilder.cdef('''
char *strdup(const char *);
void free(void *ptr);
''')
ffibuilder.compile(target='my-plugin.*', verbose=True)
And my C++ code:
#include <iostream>
#include <windows.h>
typedef char* (__stdcall *get_string_t)();
typedef void (__stdcall *free_char_t)(char*);
int main()
HINSTANCE hGetProcIDDLL = LoadLibrary("my-plugin.dll");
if (!hGetProcIDDLL)
std::cout << "could not load the dynamic library" << std::endl;
return -1;
get_string_t get_string = (get_string_t)GetProcAddress(hGetProcIDDLL, "get_string");
if (!get_string)
std::cout << "could not locate the function" << std::endl;
return -1;
free_char_t free_char = (free_char_t)GetProcAddress(hGetProcIDDLL, "free_char");
if (!free_char)
std::cout << "could not locate the function" << std::endl;
return -1;
for(int i = 0; i < 25000000; i++)
char* val = NULL;
val = get_string();
if(i % 10000 == 0)
std::cout << "Value " << i << " = " << val << std::endl;
if(val)
free_char(val);
std::cout << "End" << std::endl;
return 0;
I get this result:
Value 0 = string
Value 10000 = string
Value 20000 = string
Value 30000 = string
Value 40000 = string
Value 50000 = string
Value 60000 = string
Value 70000 = string
Value 80000 = string
Value 90000 = string
Value 100000 = string
Value 110000 = string
Value 120000 = string
Value 130000 = string
Value 140000 = string
Value 150000 = string
Value 160000 = string
Value 170000 = string
Value 180000 = string
Value 190000 = string
Value 200000 = string
Value 210000 = string
Value 220000 = string
Value 230000 = string
Value 240000 = string
Value 250000 = string
From cffi callback <function get_string at 0x03470810>:
MemoryError: Stack overflow
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
What does this error mean? I don't have memory problem because I release memory with my new free_char
function. By the way, if I remove the call to free_char
I can make all the loops (but the memory is not release).
python c++ memory-management python-cffi
This question follows this one.
I use CFFI to create a DLL and I call it from a C++ application. I was questioning myself to find how to release memory allocated by the DLL and I follow the idea mention by @metal in its answer.
Here is now my Python code:
import cffi
ffibuilder = cffi.FFI()
ffibuilder.embedding_api('''
char* get_string();
void free_char(char*);
''')
ffibuilder.set_source('my_plugin', '')
ffibuilder.embedding_init_code('''
from my_plugin import ffi, lib
@ffi.def_extern()
def get_string():
val = "string"
return lib.strdup(val.encode())
@ffi.def_extern()
def free_char(ptr):
lib.free(ptr)
''')
ffibuilder.cdef('''
char *strdup(const char *);
void free(void *ptr);
''')
ffibuilder.compile(target='my-plugin.*', verbose=True)
And my C++ code:
#include <iostream>
#include <windows.h>
typedef char* (__stdcall *get_string_t)();
typedef void (__stdcall *free_char_t)(char*);
int main()
HINSTANCE hGetProcIDDLL = LoadLibrary("my-plugin.dll");
if (!hGetProcIDDLL)
std::cout << "could not load the dynamic library" << std::endl;
return -1;
get_string_t get_string = (get_string_t)GetProcAddress(hGetProcIDDLL, "get_string");
if (!get_string)
std::cout << "could not locate the function" << std::endl;
return -1;
free_char_t free_char = (free_char_t)GetProcAddress(hGetProcIDDLL, "free_char");
if (!free_char)
std::cout << "could not locate the function" << std::endl;
return -1;
for(int i = 0; i < 25000000; i++)
char* val = NULL;
val = get_string();
if(i % 10000 == 0)
std::cout << "Value " << i << " = " << val << std::endl;
if(val)
free_char(val);
std::cout << "End" << std::endl;
return 0;
I get this result:
Value 0 = string
Value 10000 = string
Value 20000 = string
Value 30000 = string
Value 40000 = string
Value 50000 = string
Value 60000 = string
Value 70000 = string
Value 80000 = string
Value 90000 = string
Value 100000 = string
Value 110000 = string
Value 120000 = string
Value 130000 = string
Value 140000 = string
Value 150000 = string
Value 160000 = string
Value 170000 = string
Value 180000 = string
Value 190000 = string
Value 200000 = string
Value 210000 = string
Value 220000 = string
Value 230000 = string
Value 240000 = string
Value 250000 = string
From cffi callback <function get_string at 0x03470810>:
MemoryError: Stack overflow
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
From cffi callback <function get_string at 0x03470810>:
What does this error mean? I don't have memory problem because I release memory with my new free_char
function. By the way, if I remove the call to free_char
I can make all the loops (but the memory is not release).
python c++ memory-management python-cffi
python c++ memory-management python-cffi
asked Mar 24 at 10:14
PierrePierre
4572722
4572722
I just made a test with python2.7 building cffi with visual compiler aka.ms/vcpython27 and building C++ with Visual 2017, your code run till the end without problems. Which compiler did you used ?
– mpromonet
Mar 24 at 11:10
@mpromonet I usecl.exe
in Visual Studio 2010 and the last version of Python (3.7.2).
– Pierre
Mar 24 at 11:11
add a comment |
I just made a test with python2.7 building cffi with visual compiler aka.ms/vcpython27 and building C++ with Visual 2017, your code run till the end without problems. Which compiler did you used ?
– mpromonet
Mar 24 at 11:10
@mpromonet I usecl.exe
in Visual Studio 2010 and the last version of Python (3.7.2).
– Pierre
Mar 24 at 11:11
I just made a test with python2.7 building cffi with visual compiler aka.ms/vcpython27 and building C++ with Visual 2017, your code run till the end without problems. Which compiler did you used ?
– mpromonet
Mar 24 at 11:10
I just made a test with python2.7 building cffi with visual compiler aka.ms/vcpython27 and building C++ with Visual 2017, your code run till the end without problems. Which compiler did you used ?
– mpromonet
Mar 24 at 11:10
@mpromonet I use
cl.exe
in Visual Studio 2010 and the last version of Python (3.7.2).– Pierre
Mar 24 at 11:11
@mpromonet I use
cl.exe
in Visual Studio 2010 and the last version of Python (3.7.2).– Pierre
Mar 24 at 11:11
add a comment |
1 Answer
1
active
oldest
votes
From documentation of cffi :
The recommended C compiler compatible with Python 2.7 is this one:
http://www.microsoft.com/en-us/download/details.aspx?id=44266
...
For Python 3.4 and beyond:
https://www.visualstudio.com/en-us/downloads/visual-studio-2015-ctp-vs
Then you should either downgrade python or upgrade visual-studio.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322716%2fwhat-does-memoryerror-stack-overflow-mean-while-releasing-memory-using-cffi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From documentation of cffi :
The recommended C compiler compatible with Python 2.7 is this one:
http://www.microsoft.com/en-us/download/details.aspx?id=44266
...
For Python 3.4 and beyond:
https://www.visualstudio.com/en-us/downloads/visual-studio-2015-ctp-vs
Then you should either downgrade python or upgrade visual-studio.
add a comment |
From documentation of cffi :
The recommended C compiler compatible with Python 2.7 is this one:
http://www.microsoft.com/en-us/download/details.aspx?id=44266
...
For Python 3.4 and beyond:
https://www.visualstudio.com/en-us/downloads/visual-studio-2015-ctp-vs
Then you should either downgrade python or upgrade visual-studio.
add a comment |
From documentation of cffi :
The recommended C compiler compatible with Python 2.7 is this one:
http://www.microsoft.com/en-us/download/details.aspx?id=44266
...
For Python 3.4 and beyond:
https://www.visualstudio.com/en-us/downloads/visual-studio-2015-ctp-vs
Then you should either downgrade python or upgrade visual-studio.
From documentation of cffi :
The recommended C compiler compatible with Python 2.7 is this one:
http://www.microsoft.com/en-us/download/details.aspx?id=44266
...
For Python 3.4 and beyond:
https://www.visualstudio.com/en-us/downloads/visual-studio-2015-ctp-vs
Then you should either downgrade python or upgrade visual-studio.
answered Mar 24 at 14:40
mpromonetmpromonet
6,598103966
6,598103966
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322716%2fwhat-does-memoryerror-stack-overflow-mean-while-releasing-memory-using-cffi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I just made a test with python2.7 building cffi with visual compiler aka.ms/vcpython27 and building C++ with Visual 2017, your code run till the end without problems. Which compiler did you used ?
– mpromonet
Mar 24 at 11:10
@mpromonet I use
cl.exe
in Visual Studio 2010 and the last version of Python (3.7.2).– Pierre
Mar 24 at 11:11